我使用此代码添加utf8字符,一切正常。 我想在文件中更新一些行。 当我使用RandomAccessFile时utf8字符失败。 如何使用OutputStreamWriter来更新某些行?
// Add
FileOutputStream fos = new FileOutputStream(file, true);
Writer out = new OutputStreamWriter(fos, "UTF-8");
out.write(line);
out.write("\n");
out.close();
fos.close();
// Update
lineNumber=100;
RandomAccessFile randomAccessFile = new RandomAccessFile(file, "rw");
randomAccessFile.seek(lineNumber * (line.length() + 1));
randomAccessFile.writeBytes(line);
randomAccessFile.writeBytes("\n");
randomAccessFile.close();
return lineNumber;