package ls0528;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
public class RafStudy
{
public static void main(String[] args)
{
ReadFirst();
ReadSecond();
}
private static void ReadFirst()
{
try
{
RandomAccessFile raf=new RandomAccessFile(new File("D:\\ticket.txt"), "rw");
long length = raf.length();
byte[] b=new byte[529];
raf.read(b,0,b.length);
System.out.println(new String(b));
}
catch (FileNotFoundException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void ReadSecond()
{
RandomAccessFile raf;
try
{
raf = new RandomAccessFile(new File("D:\\ticket.txt"), "rw");
long length = raf.length();
raf.skipBytes(529);
byte[] b=new byte[530];
raf.read(b,0,b.length);
System.out.println(new String(b));
}
catch (FileNotFoundException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
其中文件长度为1059,所以第一次读到529