java基礎BufferedReader類(提高字元流讀取文字檔案的效率)IO流(位元組流/字元流)
String nstr=sb.toString().replace("{name}", “ok”).replace("{sex}", “男”).replace("{hobby}", “陶笛”);boolean exists( ) 判斷檔案或目錄是否存在
boolean isFile( ) 判斷是否是檔案
boolean isDirectory( ) 判斷是否是目錄
String getPath( ) 返回此物件表示的檔案的相對路徑名
String getAbsolutePath( ) 返回此物件表示的檔案的絕對路徑名
String getName( ) 返回此物件表示的檔案或目錄的名稱
boolean delete( ) 刪除此物件指定的檔案或目錄
boolean createNewFile( ) 建立名稱的空檔案,不建立資料夾
long length() 返回檔案的長度,單位為位元組, 如果檔案不存在,則返回 OL
舉例:
//建立檔案物件,建立File的實體
File file=new File(“c:\Java\hello.txt”);
if (file.exists()) {
System.out.println(“hello.txt文字存在”);
System.out.println("file是否是檔案?true是,false不是-- "+file.isFile());
System.out.println("file是否是資料夾? true是資料夾,false不是-- "+file.isDirectory());
System.out.println(“file物件的名字:”+file.getName());
System.out.println(“相對路徑:”+file.getPath());
System.out.println(“絕對路徑:”+file.getAbsolutePath());
System.out.println(“檔案長度:”+file.length()+“位元組”);
System.out.println("測試:getParent "+file.getParent());
System.out.println("測試:getParentFile "+file.getParentFile());
//刪除檔案
/*if(file.delete()){
System.out.println(“檔案刪除成功”);
}else{
System.out.println(“檔案刪除失敗”);
}*/
}else{