我想读取文本文件,然后获得文件读取的偏移量。我尝试了下面的程序,但事情是我不想使用RandomAccessFile,我该怎么做。读取文件,然后跳转到结尾
RandomAccessFile access = null;
try {
access = new RandomAccessFile(file, "r");
if (file.length() < addFileLen) {
access.seek(file.length());
} else {
access.seek(addFileLen);
}
} catch (Exception e) {
e.printStackTrace();
}
String line = null;
try {
while ((line = access.readLine()) != null) {
System.out.println(line);
addFileLen = file.length();
}
如果你不想使用RandomAccessFile,你更喜欢什么? – JRideout 2011-12-26 12:53:07
任何可以工作的东西。 – Rookie 2011-12-26 12:53:32
http://docs.oracle.com/javase/tutorial/essential/io/file.html 查找关于ByteChannels的信息 – Kris 2011-12-26 12:54:21