且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Java 解决FileInputStream读取中文时乱码的问题

更新时间:2022-02-28 07:55:32

FileInputStream fis = new FileInputStream("filePath"); // filePath为文件路径
// 声明一个字节数组
byte[] b = new byte[1024];
StringBuffer str = new StringBuffer();
int len ;
// 循环读取
while ((len = fis.read(b)) != -1) {
    str.append(new String(b, 0, len));
}

System.out.println(str.toString());