PrintStream does not record accents

2

could you help me out on a question? My code is not passing accent to the text file, even passing the encoding. (I'm reading it in notepad)

Scanner in = new Scanner(System.in);
private String texto;
public void escrever(){


        try{
            PrintStream ps = new PrintStream("saida.txt","UTF-8");
            for(;;){
            System.out.print(">> ");
            this.setTexto(in.nextLine());

            if(texto.equals("::exit")){
                System.out.print("Saindo...");
                break;
            }else{
                ps.println(this.getTexto());
                }
        }

        }catch(FileNotFoundException | UnsupportedEncodingException e){
            System.out.println(e);
        }
    }
public String getTexto() {
    return texto;
}

public void setTexto(String texto) {
    this.texto = texto;
}

I apologize for any flaw here. I'm still learning how to use the site. Thank you in advance!

    
asked by anonymous 24.02.2017 / 21:56

1 answer

1

This problem is not caused by the character encoding of PrintScream , but by using different character encodings between the Scanner and the console / terminal you are using.

To resolve this problem you can change the encoding used by NetBeans. I do not have NetBeans installed here, so I can not test but , depending on that response in

25.02.2017 / 02:00