Monday, February 13, 2012

Append the File

Before Append:
import java.io.*;

public class Append
{
    public static void main(String[] args) 
    {
  try 
  {
   DataInputStream in = new DataInputStream(System.in);
   BufferedWriter out = new BufferedWriter(new FileWriter("Buffered.java", true));
   System.out.println("How many lines?");
   int numberOfLines = Integer.parseInt(in.readLine());
   String line = "";
    
   for(int i = 0; i < numberOfLines; i++)
   {
    line = in.readLine();
    out.write("\n"+ line ); // throws IOException
   }
   out.close();
  } 
  catch (IOException e) 
  {
  }
    }
}
output:
After this check the file

No comments: