Baru -baru ini, untuk memodifikasi nama file dari sejumlah besar drama Amerika favorit, saya menulis widget menggunakan ayunan. Kode adalah bagian pemrosesan file. Konten spesifiknya adalah sebagai berikut
paket dateI.steuern; Impor java.io.bufferedReader; impor java.io.file; impor java.io.fileinputStream; impor java.io.filenotfoundException; impor java.io.fileoutputstream; impor java.filewriter; impor java.io.io exception; java.io.randomaccessfile; impor java.nio.bytebuffer; impor java.nio.channels.filechannel; impor java.util.arraylist; impor java.util.rays; impor java.util.collections; impor java.util.utillist; java.util.logging.logger; /** * * @Author S.Watson */kelas publik FileTools {public filetools () {}/** * FormatPath Escape File Directory * * @param Path * @return */public static string formatPath (string path) {return path.replaceall ("/////", "/"); } / ** * Gabungan jalur file CombinePath * * @param eins * @param zwei * @return * / private static string combinePath (string eins, string zwei) {string dori = ""; eins = null == eins? "": formatpath (eins); zwei = null == zwei? "": formatPath (zwei); if (! eins.endswith ("/") && zwei.indexof ("/")! = 0) {dori = eins + "/" + zwei; } else {dori = (eins + zwei) .replaceall ("//", "/"); } return dori; } / ** * List2Array Daftar Array Konversi * * @param Daftar * @return * / Private Static String [] List2Array (Daftar Daftar) {String Array [] = (String []) List.toArray (String baru [List.Size ()]); return array; } / ** * CP COPY FILE * * @param Source * @param Destination * @param loop * @return * / Daftar statis publik <pangkai> CP (Sumber String, Tujuan String, Loop Boolean) {Daftar <FILE> DAFTAR = NEW ARRAYLIST (); coba {file srcfile = file baru (sumber); File desfile = file baru (tujuan); list.addall (cp (srcfile, desfile, loop)); } catch (Exception ex) {j2log (null, null, ex); } daftar pengembalian; } / ** * CP COPY FILE * * @param Source * @param Destination * @param loop * @return * / Daftar statis publik <prile> CP (sumber file, tujuan file, loop boolean) {List <FILE> LIST = new ArrayList (); coba {if (! source.exists () || source.isdirectory ()) {lempar filenotfoundException baru (); } list.add (cp (sumber, tujuan)); if (loop) {string [] subfile = source.list (); untuk (string subpath: subfile) {string src = combinePath (source.getPath (), subpath); // jalur file asli dari subfile string des = combinePath (destination.getPath (), subpath); // jalur target subfile subfile = file baru (src); if (subfile.isfile ()) {list.add (cp (src, des)); } else if (subfile.isdirectory () && loop) {list.addall (cp (src, des, loop)); }}}}} catch (Exception ex) {j2log (null, null, ex); } daftar pengembalian; } / ** * CP File Single File Salin File * * @param Source * @param Destination * @return * / File statis publik CP (sumber string, string tujuan) {file desfile = null; coba {file srcfile = file baru (sumber); desfile = file baru (tujuan); desfile = cp (srcfile, desfile); } catch (Exception ex) {j2log (null, null, ex); } return desfile; } / ** * CP File Single File Salin * * @param Source * @param Destination * @return * / File statis publik CP (sumber file, tujuan file) {fileInputStream di = null; FileOutputStream out = null; FileChannel Inc = null; Filechannel outc = null; coba {if (! source.exists () || source.isdirectory ()) {lempar filenotfoundException baru (); } if (source.getPath (). Equals (destination.getPath ())) {sumber pengembalian; } long allbytes = du (sumber, false); if (! destination.exists ()) {destination.createNewFile (); } di = FileInputStream baru (Source.getPath ()); out = FileOutputStream baru (tujuan); Inc = in.getChannel (); outc = outgetchannel (); Bytebuffer bytebuffer = null; panjang panjang = 2097152; // ukuran dasar, default 2m panjang _2m = 2097152; while (inc.position () <inc.size ()) {if (allbytes> (64 * length)) {// Jika ukuran file lebih besar dari 128m, cache diubah menjadi 64m panjang = 32 * _2m; } lain jika (allbytes> (32 * length)) {// Jika ukuran file lebih besar dari 64m, cache diubah menjadi panjang 32m = 16 * _2m; } lain jika (allbytes> (16 * length)) {// Jika ukuran file lebih besar dari 32m, cache diubah menjadi 16m panjang = 8 * _2m; } lain jika (allbytes> (8 * length)) {// Jika ukuran file lebih besar dari 16m, cache diubah menjadi panjang 8m = 4 * _2m; } lain jika (allbytes> (4 * length)) {// Jika ukuran file lebih besar dari 8m, cache diubah menjadi panjang 4m = 2 * _2m; } lain jika (allbytes> (2 * length)) {// Jika ukuran file lebih besar dari 4m, cache diubah menjadi 2m panjang = _2m; } lain jika (allbytes> (panjang)) {// Jika ukuran file lebih besar dari 2m, cache diubah menjadi 1m panjang = _2m/2; } lain jika (allbytes <panjang) {// Jika file lebih kecil dari ukuran dasar, panjang output secara langsung = allbytes; } allbytes = inc.size () - inc.position (); byteBuffer = bytebuffer.allocatedIrteRect ((int) length); Inc.Read (Bytebuffer); bytebuffer.flip (); outc.write (bytebuffer); outc.force (false); }} catch (Exception ex) {j2log (null, null, ex); } akhirnya {coba {if (null! = inc) {inc.close (); } if (null! = outc) {outc.close (); } if (null! = in) {in.close (); } if (null! = out) {out.close (); }} catch (Exception ex) {j2log (null, null, ex); }} return destination; } / ** * Ubah nama file REMALAME * * @param FilePath * @param dari * @param ke * @return * / Public Static File Rename (String FilePath, String From, String to) {file newfile = null; coba {file oldFile = file baru (combainpath (filepath, from)); newfile = file baru (combainpath (filepath, to)); ganti nama (newfile, oldfile); } catch (Exception ex) {j2log (null, null, ex); } return newfile; } / ** * Ubah nama file REGIONME * * @param ke * @param dari * @return * / Public Static File Rename (file dari, file ke) {coba {string newPath = to.getPath (); String oldpath = from.getPath (); if (! oldpath.equals (newPath)) {if (! to.exists ()) {from.renameto (to); }}} catch (exception ex) {j2log (null, null, ex); } kembali ke; } / ** * MV Move File * * @param FileName * @param Source * @param tujuan * @param cover * / public static void mv (string fileName, sumber string, string tujuan, cover boolean) {coba {if (! source.Equals (tujuan)) {file oldFile = new file (combainpath (source, source.Equals (tujuan))) {file oldFile = new file (combainpath (source, filename))) {file oldFile = new file (combainpath (source, fileName))) {File oldFile = new file (combainpath (source, filename)))) {File oldFile = new file (combainpath (source, filename))) {File oldFile = new file (combainpath (source, fileName) File newfile = file baru (combainpath (tujuan, nama file)); MV (Oldfile, Newfile, Cover); }} catch (Exception ex) {j2log (null, null, ex); }} / ** * MV File Pindahkan * * @param Source * @param Destination * @param cover * / public static void mv (sumber string, string destination, cover boolean) {coba {if (! source.equals (tujuan)) {file oldFile = file baru (sumber); File newfile = file baru (tujuan); MV (Oldfile, Newfile, Cover); }} catch (Exception ex) {j2log (null, null, ex); }} / ** * MV File Pindahkan * * @param Source * @param Destination * @param cover * / public static void mv (sumber file, tujuan file, sampul boolean) {coba {if (! source.exists ()) {lempar filenotFoundException baru (); } StringBuilder fileName = new stringBuilder (source.getName ()); if (! cover && source.getPath (). Equals (destination.getPath ())) {if (filename.indexof (".")> 0) {filename.insert (filename.LastIndexof ("."), "_copy"); } else {filename.append ("_ copy"); } cp (sumber, file baru (combaintpath (source.getParent (), filename.toString ())))); } else {source.renameto (tujuan); }} catch (Exception ex) {j2log (null, null, ex); }} / ** * Ekstensi Dapatkan Informasi Ekstensi File * * @param FilePath * @param FileName * @return * / Private Static String [] Extensions (String FilePath, String FileName) {String [] Extension = {}; coba {string fullPath = CombinePath (filePath, fileName); File file = file baru (fullpath); ekstensi (file); } catch (Exception ex) {j2log (null, null, ex); } return extension; } / ** * Ekstensi Dapatkan informasi ekstensi file * * @param fullpath * @return * / private static string [] ekstensi (string fullpath) {string [] extension = {}; coba {file file = file baru (fullPath); ekstensi (file); } catch (Exception ex) {j2log (null, null, ex); } return extension; } / ** * Ekstensi Dapatkan informasi ekstensi file * * @param file * @return * / private static string [] ekstensi (file file) {string [] extension = {}; coba {if (file.isFile ()) {string filename = file.getName (); if (filename.LastIndexOf (".")> = 0) {int lastIndex = filename.LastIndexOf ("."); ekstensi [0] = string.ValueOf (lastIndex); // index of "." ekstensi [1] = filename.substring (lastIndex + 1); // ekstensi ekstensi [2] = filename.substring (0, lastIndex); // nama file}}} catch (pengecualian ex) {j2log (null, null, ex); } return extension; } / ** * ls melintasi file * * @param filepath * @param loop * @return * / Daftar statis publik <shife> ls (string filepath, loop boolean) {daftar <file> daftar = arraylist baru (); coba {file file = file baru (filepath); list.addall (ls (file, loop)); } catch (Exception ex) {j2log (null, null, ex); } daftar pengembalian; } / ** * ls melintasi file * * @param file * @param loop * @return * / Daftar statis public <prile> ls (file file, loop boolean) {daftar <pangkangkuan> daftar = arraylist baru (); coba {list.add (file); if (! File.isDirectory ()) {list.add (file); } else if (file.isDirectory ()) {file [] sublist = file.listFiles (); sublist = filessort (sublist, true); untuk (file subfile: sublist) {if (subfile.isdirectory () && loop) {list.addall (ls (subfile.getPath (), loop)); } else {list.add (subfile); }}}} catch (Exception ex) {j2log (null, null, ex); } daftar pengembalian; } / ** * Sortir File FileStort (pesanan naik default) * * @param Parentpath * @param Sublist * @return * / file statis pribadi [] filessort (file [] infiles, boolean ASC) {daftar <string> file = arraylist baru (); Daftar <String> dirs = arraylist baru (); untuk (file subfile: infiles) {if (subfile.isDirectory ()) {dirs.add (subfile.getPath ()); } else if (subfile.isfile ()) {file.add (subfile.getPath ()); }} String [] fileArray = {}; if (file.size ()> 0) {fileArray = list2Array (file); Arrays.sort (fileArray); if (! asc) {arrays.sort (fileArray, collections.reverseorder ()); }} String [] dirarray = {}; if (dirs.size ()> 0) {dirarray = list2Array (dirs); Arrays.sort (dirarray); if (! asc) {arrays.sort (dirarray, collections.reverseorder ()); }} return concat2fileArray (fileArray, dirarray); } / ** * concat2fileArray menggabungkan array file * * @param old1 * @param old2 * @return * / file statis privat [] concat2fileArray (string [] old1, string [] old2) {file [] newarray = file baru [old1.length + old2.length]; untuk (int i = 0, n = old1.length; i <n; i ++) {newArray [i] = file baru (old1 [i]); } untuk (int i = 0, j = old1.length, n = (old1.length+old2.length); j <n; i ++, j ++) {newArray [j] = file baru (old2 [i]); } return newarray; } / ** * Baca Baca File Teks * * @param FilePath * @param FileName * @param charset * @return * / public static stringBuilder baca (string filePath, string fileName, string charset) {stringBuilder sb = new stringBuilder (); coba {string fullPath = CombinePath (filePath, fileName); File file = file baru (fullpath); SB.Append (filetools.tail (file, false, 0, charset)); } catch (Exception ex) {j2log (null, null, ex); } return SB; } / ** * Baca Baca File Teks * * @param FullPath * @param Charset * @return * / Public Static StringBuilder Read (String FullPath, String Charset) {StringBuilder SB = New StringBuilder (); coba {file file = file baru (fullPath); SB.Append (filetools.tail (file, false, 0, charset)); } catch (Exception ex) {j2log (null, null, ex); } return SB; } / ** * Baca Baca File Teks * * @param File * @param charset * @return * / public static stringBuilder baca (file file, string charset) {stringBuilder sb = stringBuilder baru (); coba {sb.append (filetools.tail (file, false, 0, charset)); } catch (Exception ex) {j2log (null, null, ex); } return SB; } / ** * Temukan Baca baris yang ditentukan dari file teks * * @param filepath * @param filename * @param line * @param charset * @return * / public static stringBuilder find (string filePath, string fileName, int line, string charset) {stringBuilder sb = new stringBuilder (); coba {string fullPath = CombinePath (filePath, fileName); File file = file baru (fullpath); SB.Append (filetools.tail (file, true, line, charset)); } catch (Exception ex) {j2log (null, null, ex); } return SB; } / ** * Temukan Baca baris yang ditentukan dari file teks * * @param fullpath * @param line * @param charset * @return * / public static stringBuilder find (string fullpath, int line, string charset) {stringBuilder sb = new stringBuilder (); coba {file file = file baru (fullPath); SB.Append (filetools.tail (file, true, line, charset)); } catch (Exception ex) {j2log (null, null, ex); } return SB; } / ** * Temukan Baca baris yang ditentukan dari file teks * * file @param * @param line * @param charset * @return * / public static stringBuilder Find (file file, int line, string charset) {stringBuilder sb = new stringBuilder (); coba {sb.append (filetools.tail (file, true, line, charset)); } catch (Exception ex) {j2log (null, null, ex); } return SB; } / ** * Tail Baca file teks * * @param filepath * @param filename * @param charset * @param temukan * @param line * @return * / public static stringBuilder tail (string filePath, string filename, boolean find, int line, string charset) {stringBuilder sb = new stringbuiler (boolean, int line, string charset) {stringBuilder sb = stringbuile (boolean, int line, string charset) {stringBuilder sb = stringbuild coba {string fullPath = CombinePath (filePath, fileName); File file = file baru (fullpath); SB.Append (filetools.tail (file, find, line, charset)); } catch (Exception ex) {j2log (null, null, ex); } return SB; } / ** * ekor membaca file teks * * @param fullpath * @param charset * @param temukan * @param line * @return * / public static stringBuilder tail (string fullpath, boolean find, int line, string charset) {stringBuilder sb = new stringBuilder (); coba {file file = file baru (fullPath); SB.Append (filetools.tail (file, find, line, charset)); } catch (Exception ex) {j2log (null, null, ex); } return SB; } / ** * ekor membaca file teks * * @param file * @param charset * @param temukan * @param line * @return * / public static stringBuilder tail (file file, boolean find, int line, string charset) {stringBuilder sb = new stringBuilder (); BufferedReader BufferReader = null; if (null == charset || "" .Equals (charset)) {charset = "utf-8"; } coba {if (! File.exists () || file.isDirectory ()) {throw new filenotfoundException (); } String fullpath = file.getPath (); BufferReader = BufferedReader baru (inputStreamReader baru (FileInputStream baru (FullPath), Charset)); String temp; untuk (int i = 0; (temp = bufferreader.readline ())! = null; i ++) {if (! temukan || line == i) {sb.append (temp); }}} catch (exception ex) {j2log (null, null, ex); } akhirnya {if (null! = BufferReader) {coba {bufferreader.close (); } catch (ioException ex) {j2log (null, null, ex); }}} return SB; } / ** * Sed Baca File Teks * * @param FilePath * @param FileName * @param charset * @return * / Daftar statis publik <string> sed (string filePath, string fileName, string charset) {daftar <string> list = new arraylist (); coba {string fullPath = CombinePath (filePath, fileName); File file = file baru (fullpath); list.addall (filetools.sed (file, charset)); } catch (Exception ex) {j2log (null, null, ex); } daftar pengembalian; } / ** * sed Baca file teks * * @param fullpath * @param charset * @return * / Daftar statis publik <string> sed (string fullpath, string charset) {daftar <string> list = new arraylist (); coba {file file = file baru (fullPath); list.addall (filetools.sed (file, charset)); } catch (Exception ex) {j2log (null, null, ex); } daftar pengembalian; } / ** * Sed Baca File Teks * * @param File * @param Charset * @return * / Daftar statis publik <string> sed (File File, String Charset) {Daftar <String> Daftar = ArrayList baru (); BufferedReader BufferReader = null; if (null == charset || "" .Equals (charset)) {charset = "utf-8"; } coba {if (! File.exists () || file.isDirectory ()) {throw new filenotfoundException (); } String fullpath = file.getPath (); BufferReader = BufferedReader baru (inputStreamReader baru (FileInputStream baru (FullPath), Charset)); String temp; untuk (int i = 0; (temp = bufferreader.readline ())! = null; i ++) {list.add (temp); }} catch (Exception ex) {j2log (null, null, ex); } akhirnya {if (null! = BufferReader) {coba {bufferreader.close (); } catch (ioException ex) {j2log (null, null, ex); }}} daftar pengembalian; } / ** * Cat membaca file teks * * @param filepath * @param fileName * @return * / public static byte [] cat (string filePath, string fileName) {byte [] output = {}; coba {string fullPath = CombinePath (filePath, fileName); File file = file baru (fullpath); output = filetools.cat (file); } catch (Exception ex) {j2log (null, null, ex); } return output; } / ** * Cat membaca file teks * * @param fullpath * @return * / public static byte [] cat (string fullpath) {byte [] output = {}; coba {file file = file baru (fullPath); output = filetools.cat (file); } catch (Exception ex) {j2log (null, null, ex); } return output; } / ** * Cat membaca file teks * * @param file * @return * / public static byte [] cat (file file) {inputStream in = null; byte [] output = {}; coba {if (! file.exists () || file.isDirectory ()) {throw new fileNoTFoundException (); } String fullpath = file.getPath (); panjang panjang = du (file, false); long _2m = 2097152; byte [] bytes = byte baru [(int) panjang]; di = FileInputStream baru (FullPath); untuk (int count = 0; count! = -1;) {if (length> 16 * _2m) {length = 4 * _2m; } lain jika (panjang> 8 * _2m) {length = 2 * _2m; } lain jika (panjang> 4 * _2m) {length = _2m; } lain jika (panjang> 2 * _2m) {length = _2m / 2; } else if (length> _2m) {length = _2m / 4; } else {length = 4096; } bytes = byte baru [(int) length]; Count = in.read (bytes); output = concataRray (byte, output); length = in.available (); }} catch (Exception ex) {j2log (null, null, ex); } akhirnya {if (null! = in) {coba {in.close (); } catch (Exception ex) {j2log (null, null, ex); }}} return output; } / ** * Gabungkan array * * @param old1 * @param old2 * @return * / private static byte [] concataRray (byte [] old1, byte [] old2) {byte [] newArray = byte baru [old1.length + old2.length]; System.ArrayCopy (Old1, 0, NewArray, 0, Old1.length); System.ArrayCopy (Old2, 0, NewArray, Old1.length, Old2.length); mengembalikan newarray; } / ** * DD Tulis file konten konten fullpath * * @param filepath * @param filename * @param konten * @param isAppend * / public static void dd (string filePath, string filename, byte [] konten, boolean iSpend) {try {string fullpath = combinEpath (fileapath) File file = file baru (fullpath); Filetools.dd (file, konten, lampai); } catch (Exception ex) {j2log (null, null, ex); }} / ** * DD Tulis File Konten FullPath Konten * * @param fullpath * @param konten * @param isAppend * / public static void dd (string fullpath, byte [] konten, boolean ispend) {coba {file file = file baru (fullpath); Filetools.dd (file, konten, lampai); } catch (Exception ex) {j2log (null, null, ex); }} / ** * DD Tulis File Konten FullPath Konten * * @param File * @param konten * @param isAppend * / public static void dd (file file, byte [] konten, boolean isappend) {fileoutputStream fileOutputStream = null; coba {if (! file.exists ()) {file.createNewFile (); } fileOutputStream = new FileOutputStream (File, ISAppend); fileOutputStream.write (konten); } catch (Exception ex) {j2log (null, null, ex); } akhirnya {coba {if (null! = FileOutputStream) {fileoutputStream.close (); }} catch (ioException ex) {j2log (null, null, ex); }}}} / ** * Tulis tulis konten file untuk file fullpath * * @param filepath * @param fileName * @param konten * / public static void write (string filePath, string filename, string content) {try {string fullpath = combinePath (filePath, filename); File file = file baru (fullpath); Filetools.write (file, konten, true); } catch (Exception ex) {j2log (null, null, ex); }} / ** * Tulis tulis konten file untuk file fullpath * * @param fullpath * @param konten * / public static void write (string fullpath, string konten) {coba {file file = file baru (fullpath); Filetools.write (file, konten, true); } catch (Exception ex) {j2log (null, null, ex); }} / ** * Tulis tulis konten file untuk file fullpath * * @param file * @param konten * / public static void write (file file, konten string) {coba {filetools.write (file, konten, true); } catch (Exception ex) {j2log (null, null, ex); }} / ** * Tulis tulis (tambahkan) konten file untuk file fullpath * * @param filepath * @param filename * @param konten * @param isPend * / public static void write (string filePath, string filename, string content, boolean ispend) {try {string fullpath = combinePath (FilePath) File file = file baru (fullpath); Filetools.write (file, konten, lampai); } catch (Exception ex) {j2log (null, null, ex); }} / ** * Tulis tulis (append) konten file untuk file fullpath * * @param fullpath * @param konten * @param isAppend * / public static void write (string fullpath, string konten, boolean isappend) {coba {file file = file baru (fullpath); Filetools.write (file, konten, lampai); } catch (Exception ex) {j2log (null, null, ex); }} / ** * Tulis tulis (tambahkan) konten file untuk file fullpath * * @param file * @param konten * @param isAppend * / public static void write (file file, konten string, boolean isappend) {fileWriter fileWriter = null; coba {if (! file.exists ()) {file.createNewFile (); } fileWriter = FileWriter baru (file.getPath (), ISAppend); FileWriter.write (konten); } catch (Exception ex) {j2log (null, null, ex); } akhirnya {if (null! = fileWriter) {coba {fileWriter.close (); } catch (ioException ex) {j2log (null, null, ex); }}}}} / ** * ekor Tambahkan konten file konten ke lokasi indeks file * * @param filepath * @param fileName * @param konten * @param index * / public static void tail (string filePath, filePath string, konten string, indeks panjang) {try {string fullpath = combinePath (filePath) File file = file baru (fullpath); Filetools.tail (file, konten, indeks); } catch (Exception ex) {j2log (null, null, ex); }} / ** * ekor Tambahkan konten file konten ke lokasi indeks file * * @param fullpath * @param konten * @param index * / public static void tail (string fullpath, string konten, indeks panjang) {coba {file file = file baru (fullpath); Filetools.tail (file, konten, indeks); } catch (Exception ex) {j2log (null, null, ex); }} / ** * ekor menambahkan konten file konten ke lokasi indeks file * * @param file * @param konten * @param index * / public static void tail (file file, konten string, indeks panjang) {acakAccessFile randomAccessFile = null; coba {if (! file.exists ()) {file.createNewFile (); } randomAccessFile = baru acakAccessFile (file.getPath (), "rw"); acakeCacSfile.seek (indeks); randomAccessFile.writebytes (konten); } catch (Exception ex) {j2log (null, null, ex); } akhirnya {if (null! = randomAccessFile) {coba {randomAccessFile.close (); } catch (Exception ex) {j2log (null, null, ex); }}}}} / ** * mkdir membuat direktori * * @param filepath * @param fileName * @return * / file statis publik mkdir (string filepath, string filename) {file file = null; coba {string fullPath = CombinePath (filePath, fileName); file = file baru (fullpath); file = mkdir (file); } catch (Exception ex) {j2log (null, null, ex); } return file; } / ** * mkdir membuat direktori * * @param fullpath * @return * / file statis public mkdir (string fullpath) {file file = null; coba {file = file baru (fullpath); file = mkdir (file); } catch (Exception ex) {j2log (null, null, ex); } return file; }/** * mkdir membuat direktori * * @param file * @return */public static file mkdir (file file) {coba {if (! File.exists ()) {file.mkdir (); // Buat jika folder tidak ada}} catch (pengecualian ex) {j2log (null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null yang ” } return file; } / ** * Sentuh membuat file * * @param filepath * @param fileName * / public static void touch (string filePath, string fileName) {coba {string fullpath = combinePath (filePath, filename); File file = file baru (fullpath); sentuh (file); } catch (Exception ex) {j2log (null, null, ex); }} / ** * sentuh buat file * * @param fullpath * / public static void touch (string fullPath) {coba {file file = file baru (fullpath); sentuh (file); } catch (Exception ex) {j2log (null, null, ex); }}/** * Sentuh Buat file * * @param file */public static void touch (File file) {coba {if (! File.exists ()) {file.createNewFile (); // Buat jika file tidak ada}} catch (pengecualian ex) {j2log (null, null, ex); }} / ** * RM Hapus file * * @param filePath * @param fileName * / public static void rm (string filePath, string fileName) {coba {string fullpath = combinePath (filePath, fileName); File file = file baru (fullpath); rm (file); } catch (Exception ex) {j2log (null, null, ex); }} / ** * rm menghapus file * * @param fullpath * / public static void rm (string fullPath) {coba {file file = file baru (fullpath); rm (file); } catch (Exception ex) {j2log (null, null, ex); }} / ** * RM menghapus file * * @param file * / public static void rm (file file) {coba {if (! file.exists ()) {throw new fileNoTFoundException (); } if (file.isfile ()) {file.delete (); }} catch (Exception ex) {j2log (null, null, ex); }} / ** * Direktori Hapus RMDIR * * @param FilePath * @param FileName * @param loop * / public static void rmdir (string filePath, string filename, boolean loop) {coba {string fullpath = combinePath (filePath, fileNeName); File dir = file baru (fullpath); rmdir (dir, loop); } catch (Exception ex) {j2log (null, null, ex); }} / ** * direktori hapus rmdir * * @param fullpath * @param loop * / public static void rmdir (string fullpath, boolean loop) {coba {file dir = file baru (fullpath); rmdir (dir, loop); } catch (Exception ex) {j2log (null, null, ex); }} / ** * Direktori Hapus RMDIR * * @param dir * @param loop * / public static void rmdir (file dir, loop boolean) {coba {if (! dir.exists ()) {lempar filenotfoundException baru (); } if (dir.isdirectory ()) {file [] file = dir.listFiles (); int panjang = file.length; untuk (int i = 0; i <panjang && loop; i ++) {if (file [i] .isDirectory ()) {rmdir (file [i], loop); } else {rm (file [i]); }} if (loop || length == 0) {dir.delete (); }}} catch (exception ex) {j2log (null, null, ex); }} / ** * du Dapatkan ukuran file aktual * * @param filepath * @param fileName * @param loop * @return * / public static long du (string filePath, string fileName, loop boolean) {ukuran panjang = 0; coba {string fullPath = CombinePath (filePath, fileName); File file = file baru (fullpath); size = du (file, loop); } catch (Exception ex) {j2log (null, null, ex); } ukuran pengembalian; } / ** * du Dapatkan ukuran file aktual * * @param filepath * @param fileName * @return * / public static long du (string filePath, string fileName) {ukuran panjang = 0; coba {string fullPath = CombinePath (filePath, fileName); File file = file baru (fullpath); size = du (file, false); } catch (Exception ex) {j2log (null, null, ex); } ukuran pengembalian; } / ** * du Dapatkan ukuran file aktual * * @param fullpath * @return * / public static long du (string fullpath) {ukuran panjang = 0; coba {file file = file baru (fullPath); size = du (file, false); } catch (Exception ex) {j2log (null, null, ex); } ukuran pengembalian; } / ** * du Dapatkan ukuran file aktual * * file @param * @return * / public static long du (file file) {ukuran panjang = 0; coba {size = du (file, false); } catch (Exception ex) {j2log (null, null, ex); } ukuran pengembalian; } / ** * du Dapatkan ukuran file yang sebenarnya * * @param fullpath * @param loop * @return * / public static long du (string fullpath, boolean loop) {ukuran panjang = 0; coba {file file = file baru (fullPath); size = du (file, loop); } catch (Exception ex) {j2log (null, null, ex); } ukuran pengembalian; } / ** * du Dapatkan ukuran file aktual * * file @param * @param loop * @return * / public static long du (file file, loop boolean) {filechannel filechannel = null; Ukuran Panjang = 0; coba {if (! file.exists ()) {lempar filenotfoundException baru (); } if (file.isfile ()) {fileInputStream fis = FileInputStream baru (file); filechannel = fis.getchannel (); size = filechannel.size (); } else if (file.isDirectory ()) {file [] file = file.listFiles (); int panjang = file.length; untuk (int i = 0; i <panjang && loop; i ++) {if (file [i] .isDirectory ()) {du (file [i], loop); } else {size += du (file [i], false); }}}} catch (Exception ex) {j2log (null, null, ex); } akhirnya {if (null! = filechannel) {coba {filechannel.close (); } catch (Exception ex) {j2log (null, null, ex); }}} ukuran pengembalian; }}Di atas adalah semua tentang artikel ini, saya harap ini akan membantu untuk pembelajaran semua orang.