Java读取TXT文本文件乱码解决方案

香小蕉

关注

阅读 91

2023-04-24


 

private String[] getProjectData(File file){
       String[] data = null;
       try {
           BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file),"UTF-16"));
           String str = br.readLine();
           data = str.split("\t");
           br.close();
       } catch (FileNotFoundException e) {
           e.printStackTrace();
       } catch (IOException e) {
           e.printStackTrace();
       }
       return data;
    }

使用文件流读取,转换编码为“UTF-16”,这样乱码问题就解决了。

精彩评论(0)

0 0 举报