Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pro Android 2: What does system.out.println in Android?

Tags:

android

To the best of my (current) understanding, Android has no console to send the messages to so the System.out.println messages get lost. Instead, Log.x (outputing to LogCat) should be used.

Yet, in the acclaimed Pro Android 2 book, listing 8-1 does just that:

    in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));

    StringBuffer sb = new StringBuffer("");
    String line = "";
    String NL = System.getProperty("line.separator");
    while ((line = in.readLine()) != null) {
        sb.append(line + NL);
    }
    in.close();

    String page = sb.toString();
    System.out.println(page);

Does System.out.println really work in Android or is it only a typo?

If the former (i.e. not a typo), what does it really do and where should I expect to find the output?

like image 965
Android Eve Avatar asked Apr 12 '26 16:04

Android Eve


1 Answers

System.out.println prints to whatever is currently defined as the "standard" output PrintStream. It is possible to hook this up to point to the log stream, but really there is no good reason to use it. Use Log.x.

This is probably just a typo in the book. Nothing in that code snippet is Android specific.

like image 190
Cheryl Simon Avatar answered Apr 15 '26 04:04

Cheryl Simon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!