檔案處理工具類

2021-10-05 08:40:33 字數 2257 閱讀 9248

public class fileutils 

if (environment.media_mounted.equals(state) && dir.isdirectory() && dir.canwrite())

return false;

}/**

* 複製單個檔案

* @param oldpath

* @param newpath

*/public static void copyfile(string oldpath, string newpath)

instream.close();

}} catch (exception e)

}/**

* 複製整個資料夾內容

* @param oldpath

* @param newpath

* @return

*/public static boolean copyfolder(string oldpath, string newpath)

}file oldfile = new file(oldpath);

string files = oldfile.list();

file temp;

for (string file : files) else

if (temp.isdirectory()) else if (!temp.exists()) else if (!temp.isfile()) else if (!temp.canread()) else

fileinputstream.close();

fileoutputstream.flush();

fileoutputstream.close();

}/* 如果不需要打log,可以使用下面的語句

if (temp.isdirectory()) else if (temp.exists() && temp.isfile() && temp.canread())

fileinputstream.close();

fileoutputstream.flush();

fileoutputstream.close();}*/

}return true;

} catch (exception e)

}/**

* 刪除某個目錄下面所有檔案以及本身

* @param ppath

*/public static void deletedir(final string ppath)

public static void deletedirwihtfile(file dir)

dir.delete();// 刪除目錄本身

}/**

* 獲取資料夾大小

** @param file file例項

* @return long

*/public static long getfoldersize(file file)

} catch (exception e)

return size;

}/**

* 將檔案大小轉換成位元組

* @param fsize

* @return

*/public static string formatfilesize(long fsize)

/*** 判斷檔案是否存在

* @param strfile

* @return

*/public static boolean filei***ists(string strfile)

}catch (exception e)

return true;

}/**

* 刪除單個檔案

* @param filepath

* @return

*/public static boolean deletefile(string filepath)

return false;

}/**

* 刪除空的的資料夾

* @param tempfile

*/public static void deletedirectory(file tempfile)

for (file file: files) else if(file.isdirectory())

}tempfile.delete();

}else

}catch (exception e)

}}

日期處理工具類

public class dateutils 日期格式化 日期格式為 yyyy mm dd param date 日期 param pattern 格式,如 dateutils.date time pattern return 返回yyyy mm dd格式日期 public static strin...

shell檔案處理工具

vim etc resolve.conf 檢視dns 6.shell指令碼命令 1.diff diff file file 比較兩個檔案的不同 c 顯示周圍的行 u 按照一格式統一輸出生成補丁 r 比較兩個目錄中檔案的不同 pattch file file.path 打補丁 b 備份原檔案 2.gr...

JS日期處理工具類

此js檔案是格式化js中日期時間的工具類,其中包含了傳入日期物件date,格式化成想要的格式,或者傳入字串格式的時間個,次字串日期對應的格式可以轉換為相應的日期物件,可以計算兩個日期之間的差值 y 表示年 m 表示一年中的月份 1 12 d 表示月份中的天數 1 31 h 表示一天中的小時數 00 ...