
How to write file by line in Java

Check this out if it make any sense to you. If not able to understand then tell me.
import java.io.*;
import java.util.StringTokenizer;
class App2
{
public static void main(String... s)
{
try
{
BufferedWriter out = new BufferedWriter(new FileWriter("/home/mohit/tkt",true));
//file in which you wnt to write
String line;
BufferedReader br= new BufferedReader(new FileReader("/home/mohit/Documents/Java/file.txt"));
//data you want to enter line by line is stored in this
while((line=br.readLine())!=null)
{
StringTokenizer st=new StringTokenizer("\n");
out.write(line);
out.newLine();
}
out.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}

Hi,
For Write to a file by line using java programming language we mostly use the newLine() method of BufferedWriter class. This class of newLine() method breaks the continuous line into a separate new line. Firstly we need to create a new test file and we should give file name as(for exmple) "filebyline.txt" by the class we used. Then we also need to create another filewriter constructor that will wrapped the file object to in the stream of character. So that this (bufferedcwriter) class that provides the newline() method to write the text in a new line.