0

hello every one i am haveing problem in code i.e whenever i try to write in file it overwrite tthe previous one.I am using 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();

Edited by __avd: Added [code] tags. For easy readability, always wrap programming code within posts in [code] (code blocks).

2
Contributors
1
Reply
3
Views
7 Years
Discussion Span
Last Post by javaAddict
0

hello every one i am haveing problem in code i.e whenever i try to write in file it overwrite tthe previous one.I am using 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();

end quote.

Start a new thread next time. Always use code tags: Press the code button when you make a new post put code inside.

And mots importantly:
ALWAYS look at the API of the classes you are using. Maybe there is an option that allows you do what you want.

For example why don't you look some of the many constructors of the FileWriter class you are using. One of them might be useful.

Edited by mike_2000_17: Fixed formatting

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.