I am new to File Streams and would appreciate some help. The following code is the code I use to write to a specified file.
OutputStream outStream = new FileOutputStream(file);
outStream.write(contentsToWrite.getBytes());
outStream.close();
- How do I save different lines to a file? In my case using
\ndoes not work when writing to a file. - How do I save a line to the file without deleting the other lines?
System.lineSeparator()String.getBytes(), always use one of thegetBytesthat accepts a character set or character set name. However in this case, you would be better off using a (buffered) writer than anOutputStream.