以utf-8编码写入文件:
FileOutputStream fos = new FileOutputStream("test.txt");
OutputStreamWriter osw = new OutputStreamWriter(fos, "UTF-8");
osw.write(FileContent);
osw.flush(); 以utf-8编码读取文件:
FileInputStream fis = new FileInputStream("test.txt");
InputStreamReader isr = new InputStreamReader(fis, "UTF-8");
BufferedReader br = new BufferedReader(isr);
String line = null,FileContent = "";
while ((line = br.readLine()) != null) {
FileContent += line;
FileContent += "\r\n";
}
本文详细介绍了如何使用Java进行UTF-8编码的文件读写操作,包括以UTF-8格式写入数据到文件及从文件读取UTF-8编码的内容,帮助开发者解决字符集问题。
150

被折叠的 条评论
为什么被折叠?



