Line breaks when using DataOutputStream, Android… here is a solution to the problem.
Line breaks when using DataOutputStream, Android
I’m trying to export some data from my database to a file. I’m using DataOutputStream
because I need a method writeChars(String r)
.
The problem is that I can’t find a way to change the line. "\n"
Leave a space, but it does not change the line. Is there any way?
Solution
If you only want to write text to a file, you have chosen the wrong class. DataOuputStream.writeChars always writes characters in UTF-16BE. Use BufferedWriter or PrintWriter instead. PrintWriter.println appends platform-specific line separators to line endings. The line separator is defined by the system property line.separator and is not necessarily a single newline character (‘\n’). For example, “\r\n” for Windows, “\n” for Unix, and so on.