package txt;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.RandomAccessFile;
public class ReadTxt {
public static void main(String args[]) throws Exception{
File f = new File("d:"+File.separator+"sunpanpan"+File.separator+"dmtd"+File.separator+"dmtd_"+1+"_"+2014+".txt");
try {
RandomAccessFile raf = new RandomAccessFile(f, "r");
long len = raf.length();
String lastLine = "";
String tempLine = "";
int i=0;//控制一行多少字符
long pos = len - 1;
while (pos > 0) {
raf.seek(pos);//指针直道最后的回车
if (raf.readByte() == '\n') {
while(true){
pos=pos-1;
raf.seek(pos);
if(raf.readByte()=='\n'){
tempLine = raf.readLine();
System.out.println(tempLine);
break;
}
}
本内容试读结束,登录后可阅读更多
下载后可阅读完整内容,剩余1页未读,立即下载