First, the DataOutputStream in your second example does not serve any useful purpose 1 . Indeed, if your lines contain characters that do not fit into 8 bits, the writeBytes(String) method will distort the text. Get rid of this. Data streams are designed to read and write fine-grained binary data. For simple bytes, use a regular (or buffered) input or output stream.
Secondly, in this particular use case, when you write all the output, this is one write operation, BufferedWriter also does not add value.
So in this case. you should compare:
File f = new File("source.htm"); Writer w = new FileWriter(f); w.write("Content");
vs
File f = new File("source.htm"); OutputStream os = new FileOutputStream(f); os.write("Content".getBytes());
In my opinion, the first version looks simpler and cleaner. And it's better to use Reader and Writer stacks for text input / output ... because they are intended for them. (They take care of encoding and decoding problems, clean and transparent.)
You can compare them if you really need to know which is faster (on your system!), But I suspect that there is not much difference ... and that the first version is faster.
1 - I think DataOutputStream has buffering under covers, but for this use case, buffering does not help performance.
In cases where you are executing multiple (small) records, rather than large ones, there is a significant performance advantage when using BufferedWriter (or BufferedOutputStream ) instead of an unbuffered writer or stream.
Another point is that both versions of your code use the default character encoding for the platform to encode the output file. It may be more appropriate to use a specific encoding regardless of the default value or to make it a configuration parameter or command line.