try{
File file = new File(\"write.txt\");
FileWriter writer = new FileWriter(file);
PrintWriter printWriter = new PrintWriter(writer);
printWriter.prin
From the source what PrintWriter does when you pass a File is to open it in a buffered way
public PrintWriter(File file) throws FileNotFoundException {
this(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file))),
false);
}
if you pass it a FileWriter, it will open it, without buffering
public FileWriter(File file) throws IOException {
super(new FileOutputStream(file));
}
This means that the first example can be slightly more efficient. However I would use the File
without the FileWriter
because to me it is simpler.