writing to a file (wrapping)

Hello,

I have been trying the following two ways to create an object to write to a file named "out.txt" :

import java.io.*;

publicclass Test{

publicstaticvoid main(String[] args)throws Exception{

BufferedWriter writer =new BufferedWriter(new PrintWriter(new FileWriter("out.txt")));//WAY 1: WORKS

PrintWriter writer =new PrintWriter(new BufferedWriter(new FileWriter("out.txt")));//WAY 2: WORKS

}

}

It looks like that both ways, tried individually, compile with no errors. Basically I exchange the wrapping betweeing BufferedWriter and PrintWriter. So I wish to ask if one way is considered "correct" over the other, or if there are other subtle differences (perhaps at runtime) that I am not aware of... Many Thanks.

[1432 byte] By [DeChristoa] at [2007-11-26 19:41:27]
# 1
well no both ways are fine.s = new Scanner(new BufferedReader (new FileReader("abc.txt")));
lrngjavaa at 2007-7-9 22:22:39 > top of Java-index,Java Essentials,New To Java...
# 2
Without knowing more about exactly what kind of file you want to write, I'd suggest:BufferedWriter bw = new BufferedWriter(new FileWriter("out.txt:));I do not know why you'd want to chain BufferedWriter and PrintWriter.
abillconsla at 2007-7-9 22:22:39 > top of Java-index,Java Essentials,New To Java...
# 3
Thanks to both.. It looks like that these two ways are the same, but there's a simpler way to do it too..
DeChristoa at 2007-7-9 22:22:39 > top of Java-index,Java Essentials,New To Java...