简体   繁体   中英

Java Printwriter Encoding UTF-8

File file2 = new File("output.txt");
    FileWriter fileWriter = new FileWriter(file2, true);


    PrintWriter out = new PrintWriter(fileWriter);
            out.println("üçı");
            out.close();

My code is here. I want to write to the file with encode UTF-8. Please help.

Try this please. this must work for you(i hope)

    OutputStreamWriter outputStreamWriter = new OutputStreamWriter(new FileOutputStream(file2), Charset.forName("UTF-8"));
    PrintWriter out = new PrintWriter(outputStreamWriter);
    out.print("سلام");

maybe this will solve your problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM