0
点赞
收藏
分享

微信扫一扫

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


 

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 条评论