java fileinputstream中文乱码
作者:
Mracale | 来源:发表于
2021-09-18 09:45 被阅读0次public static void main(String[] args) throws IOException {
// 创建File对象
File file = new File("C:\\Users\\Desktop\\test.txt");
InputStream fis=null;
try {
fis = new FileInputStream(file);
InputStreamReader reader = new InputStreamReader(fis,"UTF-8"); //最后的"GBK"根据文件属性而定,如果不行,改成"UTF-8"试试
BufferedReader br = new BufferedReader(reader);
String line;
while ((line = br.readLine()) != null) {
System.out.println(line);
}
br.close();
reader.close();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (fis != null) {
try {
fis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
本文标题:java fileinputstream中文乱码
本文链接:https://www.haomeiwen.com/subject/hfmegltx.html
网友评论