//用RandomAccessFile读取出来乱码的解决
String path = "d:/test.txt";
RandomAccessFile raf = null;
String line = null;
try {
raf = new RandomAccessFile(path, "rw");
while ((line = raf.readLine()) != null) {
line = new String(line.getBytes("8859_1"), "gb2312");//转变编码格式
System.out.println(line);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
raf.close();
} catch (IOException e) {
e.printStackTrace();
}
}
//用RandomAccessFile写入文件乱码的解决
raf.write(str.getBytes());
本文介绍如何使用RandomAccessFile处理文件读取与写入时出现的乱码问题,通过转换编码格式来确保数据正确读写。
5218

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



