Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

PrintStream v/s PrintWriter

807597Jul 5 2005 — edited Jul 8 2005
In the folloowing code, I have used PrintStream to output some text to a file.

package src;
import java.io.*;

public class Sample {

public static void main(String[] args) {
PrintStream out = null;
try{
out = new PrintStream("c:\\jay.txt");
}
catch(Exception e){
e.printStackTrace();
}
out.println("This is test");
out.close();
}
}

If, instead I use PrintWriter class instance in place of PrintStream, I get the same result. The resultant file is of the same size and displays the same text. Here I have got confused... I want to confess that I have no clue why this is happening... I thought PrintStream puts characters in 8-bit format and PrintWriter in 16-bit format... How come the editor I use to open the file interpret both the formats...
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 5 2005
Added on Jul 5 2005
5 comments
535 views