print special characters when generating file

3

Some strings are coming out like this at the time of generating my .txt

É fácil entrar em contato com a área 

I read another .txt file that has several phrases, I make a treatment of all the lines and I separate the part that interests me, hence I generate a .txt file It's just going out like this. Do you have any way to solve it?

    Reader lerArquivo = new FileReader(getNomeArquivo());
    BufferedReader br2 = new BufferedReader(lerArquivo);

    String linha;

    while ((linha = br2.readLine()) != null) {

    }

// to generate the file I use

FileWriter x = new FileWriter("geraArquivo.txt", false);
x.write(organizaString);
    
asked by anonymous 17.06.2015 / 19:45

2 answers

4

Instead of using FileReader , use InputStreamReader and pass charset .

Example:

BufferedReader br2 = new BufferedReader(
                         new InputStreamReader(new FileInputStream(getNomeArquivo()), "UTF8"));
    
17.06.2015 / 19:53
0
File arq = new File(nomeArq);

// para ler
BufferedReader leitor = new BufferedReader(new InputStreamReader(new FileInputStream(arq.getPath()), "ISO-8859-1"));

// para escrever
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(arq.getPath()), "ISO-8859-1"));
    
10.11.2017 / 13:20