DataInputStream in =new DataInputStream(new BufferedInputStream(new FileInputStream("passwd.txt")));
while(in.available() != 0)
{
content =content +(char)in.readByte();
}
in.close();
while(in.available() != 0)
{
content =content +(char)in.readByte();
}
in.close();
我的应用背景是:
别人用delphi一次往文件写一行,我读的时候,首先要跳过已经处理过的行。我的计划是每次读完后保存读的行数,下次读时先跳过这些行,然后继续对这些行以下行进行处理。
用java能实现一次读一行吗?
import java.io.*;
String str;
BufferReader br=new BufferReader(new FileReader("d:\test.txt"))
while (true)
{
str=br.readLine();
if (str==null)
{
break;
}
System.out.println(str);
}