java 记事本读取文本文件的乱码问题,终于解决了 O(∩_∩)O~ 多谢 uu老师帮助
void readFile(String path) // 显示打开文件的内容
{
try
{
File file = new File(path);
BufferedReader br = new BufferedReader(new InputStreamReader(
new FileInputStream(file), "gb2312"));// 编码转换(关键的地方)
String str = "";
int size = (int) file.length();
int charRead = 0;
char[] content = new char[size];
while (br.ready())
{
charRead += br.read(content, charRead, size - charRead);
}
br.close();
str = new String(content, 0, charRead);
text.setText(str);
} catch (IOException e)
{
System.out.println("读取文件出错");
}
}