hello i am trying to write in file and when ever i do this previous lines overwrites in file .i am trying this code
File f=new File("c:\\paul.txt");
//f.createNewFile();
BufferedWriter br = new BufferedWriter(new FileWriter(f));
BufferedReader br1=new BufferedReader (new InputStreamReader(System.in));
FileReader fr=new FileReader(f);
// FileWriter frt=new FileWriter(f);
// BufferedReader brz=new BufferedReader(fr);

String text;

System.out.println("Enter value");
text= br1.readLine();

// br.newLine();
// br.append(text);
br.newLine();
br.write(text);
br.flush();
// frt.write(text);

br.close();

See the API docs. You can add another argument to your FileWriter constructor call so that it appends rather than overwrites.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.