重慶分公司,新征程啟航
為企業提供網站建設、域名注冊、服務器等服務
為企業提供網站建設、域名注冊、服務器等服務
這期內容當中小編將會給大家帶來有關java判斷抽象路徑名是否為文件的方法,文章內容豐富且以專業的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。
創新互聯建站是一家專注于成都做網站、網站制作、成都外貿網站建設與策劃設計,土默特左旗網站建設哪家好?創新互聯建站做網站,專注于網站建設十余年,網設計領域的專業建站公司;建站業務涵蓋:土默特左旗等地區。土默特左旗做網站價格咨詢:13518219792
java.io.File.isFile() 檢查表示此抽象路徑名的文件是否是一個正常的文件。表示此抽象路徑名的文件是一個文件,該方法返回true,否則該方法返回false。
異常
SecurityException -- 如果安全管理器存在并且其SecurityManager.checkRead(java.lang.String) 方法拒絕對文件的讀訪問
例子
下面的示例演示java.io.File.isFile()方法的用法。
package com.test; import java.io.File; public class FileDemo { public static void main(String[] args) { File f = null; String path; boolean bool = false; try{ // create new file f = new File("c:"); // true if the file path is a file, else false bool = f.isFile(); // get the path path = f.getPath(); // prints System.out.println(path+" is file? "+ bool); // create new file f = new File("c:/test.txt"); // true if the file path is a file, else false bool = f.isFile(); // get the path path = f.getPath(); // prints System.out.print(path+" is file? "+bool); }catch(Exception e){ // if any error occurs e.printStackTrace(); } } }
讓我們編譯和運行上面的程序,這將產生以下結果:
c: is file? false c:est.txt is file? true
上述就是小編為大家分享的java判斷抽象路徑名是否為文件的方法了,如果剛好有類似的疑惑,不妨參照上述分析進行理解。如果想知道更多相關知識,歡迎關注創新互聯行業資訊頻道。