I need to write to a file without losing the contents of said file. What is the correct code? This is the code I'm using, but when I re-run the program, the file will lose its previous contents:
Thanks.Code:import java.io.*; class abc { public static void main(String[] args) throws IOException { BufferedReader a =new BufferedReader(new InputStreamReader(System.in)); System.out.println("Please type something..."); String b = a.readLine(); PrintStream c = new PrintStream(new FileOutputStream("abc.txt")); c.println(b); c.close(); } }


Reply With Quote


Bookmarks