import java.io.*;
public class test
{
public static void main(String args[]) throws Exception{
FileInputStream fin=new FileInputStream("F:\\sample.txt");
byte[] by=new byte[1000];
int size=fin.available();
if(size==0){
System.out.println("文件为空!!");
}else{
int len=fin.read(by);
System.out.println(new String(by,0,len));
}
}
}
![](https://video.ask-data.xyz/img.php?b=https://iknow-pic.cdn.bcebos.com/9d82d158ccbf6c81e4c85ca8bd3eb13532fa40f6?x-bce-process=image%2Fresize%2Cm_lfit%2Cw_600%2Ch_800%2Climit_1%2Fquality%2Cq_85%2Fformat%2Cf_auto)
关键是这一句,这一句能判断文件是否为空