一个TXT文件有3行,我读取第一行,指针就指向了第2行,所以我一输出就把第2行改了,我希望改的是第1行。
用seek() 我不知道中间的参数是多少可以退回第1行 seek(getFilePointer()- n) n 应该怎么算??;
另writeBytes 无法输出中文import java.io.*;
public class Hello {
public static void main(String[] args)
{
String str = new String();
try{
RandomAccessFile read = new RandomAccessFile("aaa.txt","rw");
str = read.readLine();
System.out.println(str);
read.writeBytes("aaaaa");
}
catch(FileNotFoundException e)
{
e.printStackTrace();
}
catch(IOException e)
{
e.printStackTrace();
}
}
}