ken021600
asked on
print to output window
Hi experts,
I have a question about "printing to output window". if i want to print some stuff to the output window, one way is:
System.out.println("hello" );
an alternative way is:
FileWriter fw = new FileWriter(FileDescriptor. out);
PrintWriter pw = new PrintWriter(fw);
pw.println("hello");
any difference between these two approaches? Thank you for your help.
ken
I have a question about "printing to output window". if i want to print some stuff to the output window, one way is:
System.out.println("hello"
an alternative way is:
FileWriter fw = new FileWriter(FileDescriptor.
PrintWriter pw = new PrintWriter(fw);
pw.println("hello");
any difference between these two approaches? Thank you for your help.
ken
hi !
think the other differences is ur program will take up more resources as the System.out is already define, no point define a new priwriter just for this purposes(printing hello to screen) :P
haha
think the other differences is ur program will take up more resources as the System.out is already define, no point define a new priwriter just for this purposes(printing hello to screen) :P
haha
ASKER
Thanks a lot for your help.
anyways,i have to point out:
1)"println" and "print" are not the issue, just a typo.
2)I've already checked out the java API. I posted this question here coz i didn't get anything from reading the API, not coz i'm lazy...so what on earth are the differences between PrintStream and PrintWriter?
3)printing "hello" to the standard output is just a simple way to ask this question. it makes life easier without losing the point...
thanks,
ken
anyways,i have to point out:
1)"println" and "print" are not the issue, just a typo.
2)I've already checked out the java API. I posted this question here coz i didn't get anything from reading the API, not coz i'm lazy...so what on earth are the differences between PrintStream and PrintWriter?
3)printing "hello" to the standard output is just a simple way to ask this question. it makes life easier without losing the point...
thanks,
ken
They handle new line and flushing differently:
PrintStream uses '\n' as a new line character.
PrintWriter uses the system defined new line character.
PrintStream autoflushs whenever a new line character appears in input.
PrintWriter only autoflushs if a println() is called.
PrintStream uses '\n' as a new line character.
PrintWriter uses the system defined new line character.
PrintStream autoflushs whenever a new line character appears in input.
PrintWriter only autoflushs if a println() is called.
ASKER
aha you are Aussie! (i live in Sydney anyway)i didn't know that till just now...i had a look at your profile.
Thanks for your help. but why did those Java developers bother to develop two ways to do it?
thanks,
ken
Thanks for your help. but why did those Java developers bother to develop two ways to do it?
thanks,
ken
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
cheers mate!
ken
ken
Only a B :-)
Thanks for the points.
Thanks for the points.
Your example uses a println in one case, and a print in the other so this will also cause a difference.