Problem generating .txt files with IntelliJ IDEA
Hi!
I have an issue generating .txt files with IntelliJ IDEA. I use the simplest version of creating .txt files i.e. with BufferedWriter/BufferedReader like this:
- for writing:
try { BufferedWriter bw = new BufferedWriter(new FileWriter("points.txt")); bw.write(points); bw.close();}catch (IOException e){ e.printStackTrace();}
- for reading:
File file = new File("points.txt");if(file.exists()) { try { BufferedReader br = new BufferedReader(new FileReader(String.valueOf(file.toPath()))); System.out.println(br.readLine()); br.close(); } catch (Exception e) { e.printStackTrace(); }}
But when I open the .txt file both in IntelliJ IDEA or in Notepad, the content is encoded and unreadable.
How can I generate readable plain .txt files with IntelliJ IDEA?
Many thanks!
Sammy
Please sign in to leave a comment.
Hi Samy Sylvester
It could be related to the data you're writing. Please verify:
* File | Settings | Editor | File Encodings (Windows/Linux)
* IntelliJ IDEA | Settings | Editor | File Encodings (macOS)
Hi Monica!
Thank you very much for your kind answer! I'll keep in mind all the information you offered me here! Also, your answer helped me solving my issue on this subject, since my “points" variable was an integer and converting it to String made the content from the .txt file completely readable! :)
Wishing you all the best, I thank you for your support!
Sammy
It's a pleasure to help. Good, your .txt is readable now!