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.len
java 使用RandomAccessFile随机文件流 把一个文件分两次读取
最新推荐文章于 2022-08-13 21:26:51 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)