java怎样判断一个文件中是否存在内容
2个回答
展开全部
package test1701;
import java.io.FileInputStream;
import java.io.IOException;
public class Test10 {
public static void main(String[] args){
String path = "文件路径";
FileInputStream fileInputStream = null;
try {
fileInputStream = new FileInputStream(path);
if(fileInputStream.available() == 0){
System.out.println("文件为空");
}
} catch (Exception e) {
e.printStackTrace();
}finally{
if(fileInputStream != null){
try {
fileInputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询