Answer the question
In order to leave comments, you need to log in
How to write data to file.txt with BufferedWriter or FileWriter?
I am writing text data to a file by code
public void writer (String file, ArrayList array) throws IOException{
BufferedWriter writter = new BufferedWriter(new FileWriter(file));
for (String s: array){
writter.write(s + "\n");
}
writer.close();
}
it works fine, BUT if the text is like this -> "Secrétaire général / Generalsekretär"
then it writes it like this -> "Secr?taire g?n?ral / Generalsekret?r"
I work in Netbeans, and if I start the project in it, it writes normally, but if I run the already assembled file from windows, it writes with such characters, I read that the text encoding might not be the same, but I didn’t understand how to fix it. Or is it not the coding? maybe there are some examples?
Answer the question
In order to leave comments, you need to log in
OutputStreamWriter writer =
new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8)); // тут можно указать кодировку
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question