Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.
Writing to a File using PrintWriter and FileWriter?
Having a bit of trouble writing to a File. If I populate the .txt File and use a FileReader with a BufferedReader like this:
[code]BufferedReader in = new BufferedReader(new FileReader("password.txt"));
String input = in.readLine();[/code]
I can read the contents of the File. But when it comes to writing to the .txt File using a PrintWriter and a FileWriter like this:
[code]PrintWriter out = new PrintWriter(new FileWriter("password"));
The .txt File just becomes empty, even if the File doesn't exist or is empty to begin with, all I get is an empty File. I'm a bit confused, and was wondering if anyone could shine some light on the matter, and tell me how to go about writing to a .txt File successfully. I've even tried a RandomAccessFile to write to a file, without any luck. So any help on writing to a File using a PrintWriter and a FileWriter would be appreciated.
Thanks in advance,
0 · ·