关于文件结束符~~~~

isaxu 2003-06-12 09:26:39
要对一个文件流进行读操作,
RandomAccessFile fin = new RandomAccessFile("matchTable.dat","r");
怎样判断是否已经读到文件结尾了呢?
while(fin.read() !='EOF')
这个文件结束符编译通不过阿~~~~
请各位大虾指教拉~
3Q!^_^
...全文
425 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
jerrygui 2003-06-12
  • 打赏
  • 举报
回复
int bytes_read;
byte[] buffer = new byte[4096]; // To hold file contents
while((bytes_read = fin.read(buffer)) != -1)

断是否已经读到文件结尾了
zh_baiyu 2003-06-12
  • 打赏
  • 举报
回复
up ~
yuanmeng163 2003-06-12
  • 打赏
  • 举报
回复
RandomAccessFile fin = new RandomAccessFile("matchTable.dat","r");
long filePoint = 0;//文件指针
long fileLength = fin.length();//获得文件的长度
while(filePoint < fileLength) {//指针小于文件的长度,则不到文件结尾
System.out.println(fin.readLine());
filePoint = fin.getFilePointer();//读过文件内容后得到当前指针的位置
}
nicklegao 2003-06-12
  • 打赏
  • 举报
回复
byte[] bBytes = new byte[102400];
FileInputStream infile = new FileInputStream(a);
FileOutputStream outfile = new FileOutputStream(b);
int nRead ;
while ((nRead = infile.read(bBytes, 0, 102400)) > 0) {
outfile.write(bBytes,0,nRead);
}
infile.close();
outfile.close();

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧