首页 > IOUtils:读取文件转字符串,中文字符无法转换

IOUtils:读取文件转字符串,中文字符无法转换

public class ConvertFile2String {
    public static void main(String[] args) throws FileNotFoundException, IOException {
        File file=new File("E:\\Code\\Jretec\\PCBwebsiteProject\\PCBProject\\新建文本文档.txt");
        InputStream in=new FileInputStream(file);
//        String str=IOUtils.toString(in,"utf-8");
        StringWriter writer = new StringWriter();
        IOUtils.copy(in, writer, "utf-8");
        String str = writer.toString();
        System.out.println(str);
    }
}
【热门文章】
【热门文章】