Read and Write Text in ANSI format

前端 未结 1 869
南旧
南旧 2020-12-01 05:37

Please have a look at the following code

import java.io.*;

public class CSVConverter 
{
    private File csvFile;
    private BufferedReader reader;
    pri         


        
相关标签:
1条回答
  • 2020-12-01 06:05

    To read a text file with a specific encoding you can use a FileInputStream in conjunction with a InputStreamReader. The right Java encoding for Windows ANSI is Cp1252.

    reader = new BufferedReader(new InputStreamReader(new FileInputStream(csvFile), "Cp1252"));
    

    To write a text file with a specific character encoding you can use a FileOutputStream together with a OutputStreamWriter.

    writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), "Cp1252"));
    

    The classes InputStreamReader and OutputStreamWriter translate between byte oriented streams and text with a specific character encoding.

    0 讨论(0)
提交回复
热议问题