New Line BufferedWriter Java uses newLine() method to give new line in the destination file. Example given.
But before going into example and explanation, let us see what DataOutputStream will do with new line in the destination file. DataOutputStream does not have a builtin method. Infact, new line is OS dependent. \n works in System.out.print(). \n reads the new line character from OS and replaces \n. This we have seen with example in DataOutputStream New Line Java.
Now let us go for Example on New Line BufferedWriter Java
public class UsingNewLine
public static void main(String args) throws IOException
BufferedWriter bw = new BufferedWriter(new FileWriter("def.txt"));
First two lines gets in a single line. And the last two in different lines due to addition of new line character with newLine() method.
Increase your Java knowledge with all View All for Java Differences on 80 Topics