1.exists()方法使用
//這裏使用new 創建實例,所以f不可能爲null
File f = new File("D:/xyz/hashdog.text")
//用exists()方法判斷
if(!f.exists()){
System.out.print("該文件不存在")
}
2.!=null條件使用
//這裏使用new 創建實例,所以f不可能爲null
File f ;
//xxx代表業務中的條件表達式
if(xxx){
f = new File("D:/xyz/hashdog.text")
}
//這裏要使用!=null判斷,可能存在空指針
if(f != null && !f.exists()){
System.out.print("該文件不存在")
}