في الآونة الأخيرة ، من أجل تعديل أسماء الملفات لعدد كبير من الدراما الأمريكية المفضلة ، كتبت عنصر واجهة مستخدم باستخدام الأرجوحة. الرمز هو جزء معالجة الملفات. المحتوى المحدد كما يلي
حزمة Datei.SteUern ؛ استيراد java.io.bufferedreader ؛ استيراد java.io.file ؛ استيراد java.io.fileinputStream ؛ استيراد java.io.filenotfoundexception ؛ import java.io.fileOutputStream ؛ استيراد java.io.filewriter java.io.randomaccessfile ؛ استيراد java.nio.bytebuffer ؛ استيراد java.nio.channels.filechannel ؛ استيراد java.util.arraylist ؛ java.util.logging.logger ؛ /** * * Author S.Watson */Public Class FileTools {Public FileTools () {}/** * FormatPath Depress File Directory * * param path * return */public Static String FormatPath (مسار السلسلة) {return path.replaceall ("////" ، "/"/") } / ** * combinepath patph path path merge * * param eins * param zwei * @regurn * / private static string combinePath (string eins ، string zwei) {String dori = "" ؛ eins = null == eins؟ "": formatpath (eins) ؛ zwei = فارغة == zwei؟ "": formatpath (zwei) ؛ if (! eins.endswith ("/") && zwei.indexof ("/")! = 0) {dori = eins + "/" + zwei ؛ } آخر {dori = (eins + zwei) .replaceall ("//" ، "/") ؛ } إرجاع دوري ؛ } / ** * list2array قائمة تحويل قائمة * * param list * return * / private static string [] list2array (قائمة قائمة) {String Array [] = (string []) list.toarray (new string [list.size ()]) ؛ مجموعة العودة } / ** * cp copy file * * param source * param الوجهة * param loop * return * / قائمة ثابتة عامة <file> cp (مصدر السلسلة ، الوجهة السلسلة ، حلقة منطقية) {list <file> list = new ArrayList () ؛ حاول {file srcfile = ملف جديد (المصدر) ؛ ملف desfile = ملف جديد (الوجهة) ؛ list.addall (CP (srcfile ، desfile ، loop)) ؛ } catch (استثناء ex) {j2log (null ، null ، ex) ؛ } قائمة الإرجاع ؛ } / ** * cp copy file * * param source * param الوجهة * param loop * return * / قائمة ثابتة عامة <file> cp (مصدر الملف ، وجهة الملف ، حلقة Boolean) {list <file> list = new ArrayList () ؛ جرب {if (! source.exists () || source.isdirectory ()) {throw new FileNotfoundException () ؛ } list.add (cp (source ، الوجهة)) ؛ if (loop) {string [] subfile = source.list () ؛ لـ (String subpath: subfile) {String src = combinePath (source.getPath () ، subpath) ؛ // مسار الملف الأصلي لسلسلة subfile des = combinePath (destination.getPath () ، subpath) ؛ // المسار الهدف من ملف subfile subfile = جديد (src) ؛ if (subfile.ispile ()) {list.add (cp (src ، des)) ؛ } آخر if (subfile.isdirectory () && loop) {list.addall (cp (src ، des ، loop)) ؛ }}}}} catch (استثناء ex) {j2log (null ، null ، ex) ؛ } قائمة الإرجاع ؛ } / ** * CP ملف نسخ ملف واحد * * param المصدر * param الوجهة * return * / public static file cp (مصدر السلسلة ، واجهة السلسلة) {file desfile = null ؛ حاول {file srcfile = ملف جديد (المصدر) ؛ desfile = ملف جديد (الوجهة) ؛ desfile = cp (srcfile ، desfile) ؛ } catch (استثناء ex) {j2log (null ، null ، ex) ؛ } إرجاع Desfile ؛ } / ** * CP ملف نسخ ملف واحد * * param المصدر * param الوجهة * @REGARN * / public static file cp (مصدر الملف ، وجهة الملف) {fileInputStream in = null ؛ fileOutputStream Out = null ؛ FILECHANNEL INC = NULL ؛ filechannel outc = null ؛ جرب {if (! source.exists () || source.isdirectory ()) {throw new FileNotfoundException () ؛ } if (source.getPath (). equals (destination.getPath ())) {return source ؛ } long allbytes = du (المصدر ، خطأ) ؛ if (! destination.exists ()) {destination.createNewFile () ؛ } في = جديد fileInputStream (source.getPath ()) ؛ out = fileOutputStream (الوجهة الجديدة) ؛ inc = in.getChannel () ؛ outc = out.getChannel () ؛ bytebuffer bytebuffer = null ؛ الطول الطويل = 2097152 ؛ // الحجم الأساسي ، الافتراضي لمدة 2 متر _2m = 2097152 ؛ بينما (inc.position () <inc.size ()) {if (allbytes> (64 * length)) {// إذا كان حجم الملف أكبر من 128 مترًا ، يتم تغيير ذاكرة التخزين المؤقت إلى 64 مترًا = 32 * _2m ؛ } آخر إذا (allbytes> (32 * طول)) {// إذا كان حجم الملف أكبر من 64m ، يتم تغيير ذاكرة التخزين المؤقت إلى طول 32 متر = 16 * _2m ؛ } آخر إذا (allbytes> (16 * طول)) {// إذا كان حجم الملف أكبر من 32 متر ، يتم تغيير ذاكرة التخزين المؤقت إلى 16 مترًا = 8 * _2m ؛ } if if (allbytes> (8 * length)) {// إذا كان حجم الملف أكبر من 16 مترًا ، يتم تغيير ذاكرة التخزين المؤقت إلى طول 8m = 4 * _2m ؛ } if if (allbytes> (4 * length)) {// إذا كان حجم الملف أكبر من 8m ، يتم تغيير ذاكرة التخزين المؤقت إلى طول 4M = 2 * _2M ؛ } if if (allbytes> (2 * length)) {// إذا كان حجم الملف أكبر من 4M ، يتم تغيير ذاكرة التخزين المؤقت إلى طول 2M = _2M ؛ } if if (allbytes> (length)) {// إذا كان حجم الملف أكبر من 2M ، يتم تغيير ذاكرة التخزين المؤقت إلى 1m طول = _2m/2 ؛ } آخر إذا (allbytes <length) {// إذا كان الملف أصغر من حجم الأساس ، وطول الإخراج مباشرة = allbytes ؛ } allbytes = Inc.Size () - Inc.Position () ؛ bytebuffer = bytebuffer.allocatedirect ((int) طول) ؛ Inc.Read (Bytebuffer) ؛ bytebuffer.flip () ؛ OutC.Write (Bytebuffer) ؛ Outc.force (false) ؛ }} catch (استثناء ex) {j2log (null ، null ، ex) ؛ } أخيرًا {try {if (null! = inc) {Inc.Close () ؛ } if (null! = outc) {outC.Close () ؛ } if (null! = in) {in.close () ؛ } if (null! = out) {out.close () ؛ }} catch (استثناء ex) {j2log (null ، null ، ex) ؛ }} وجهة الإرجاع ؛ } / ** * إعادة تسمية ملف إعادة تسمية * * param filepath * param من * param إلى * regurn * / public static file rename (String filepath ، string from ، string to) {file newFile = null ؛ حاول {file oldfile = new file (combainPath (filepath ، from)) ؛ newFile = ملف جديد (combainpath (filepath ، إلى)) ؛ إعادة تسمية (NewFile ، Oldfile) ؛ } catch (استثناء ex) {j2log (null ، null ، ex) ؛ } إرجاع جديد ؛ } / ** * إعادة تسمية ملف إعادة تسمية * * param إلى * param من * regurn * / إعادة تسمية الملف الثابت العام (ملف من ، ملف إلى) {try {string newPath = to.getPath () ؛ String OldPath = from.getPath () ؛ if (! oldpath.equals (newPath)) {if (! to.exists ()) {from.renameto (to) ؛ }}} catch (استثناء ex) {j2log (null ، null ، ex) ؛ } العودة إلى ؛ } / ** * MV نقل ملف * * param filename * param المصدر * param الوجهة * param cover * / public static void mv (اسم ملف السلسلة ، مصدر السلسلة ، وجهة السلسلة ، الغلاف المنطقي) {try {if (! source.equals (الوجهة)) {file oldfile = combainpath (source ، filename)) ؛ ملف newFile = ملف جديد (combainPath (الوجهة ، اسم الملف)) ؛ MV (Oldfile ، newfile ، cover) ؛ }} catch (استثناء ex) {j2log (null ، null ، ex) ؛ }} / ** * mv نقل ملف * * param المصدر * param الوجهة * param cover * / public static void mv (مصدر السلسلة ، الوجهة السلسلة ، غطاء منطقي) {try {if (! source.equals (الوجهة)) {file oldfile = ملف جديد (المصدر) ؛ ملف newFile = ملف جديد (الوجهة) ؛ MV (Oldfile ، newfile ، cover) ؛ }} catch (استثناء ex) {j2log (null ، null ، ex) ؛ }} / ** * mv نقل ملف * * param المصدر * param الوجهة * param cover * / public static void mv (مصدر الملف ، وجهة الملف ، غطاء منطقي) {try {if (! source.exists ()) {رمي filenotfoundexception () ؛ } stringbuilder filename = new StringBuilder (source.getName ()) ؛ if (! cover && soutt.getPath (). equals (destination.getPath ())) {if (filename.indexof (". } آخر {filename.append ("_ copy") ؛ } cp (المصدر ، ملف جديد (combainPath (source.getParent () ، filename.toString ())))) ؛ } آخر {source.renameto (الوجهة) ؛ }} catch (استثناء ex) {j2log (null ، null ، ex) ؛ }} / ** * امتدادات الحصول على معلومات تمديد الملف * * param filepath * param filename * regurn * / private static string [] extensions (String filepath ، اسم ملف السلسلة) {string [] extension = {} ؛ حاول {String FullPath = CombatePath (FilePath ، filename) ؛ ملف الملف = ملف جديد (FullPath) ؛ الامتدادات (ملف) ؛ } catch (استثناء ex) {j2log (null ، null ، ex) ؛ } تمديد الإرجاع ؛ } / ** * امتدادات الحصول على معلومات تمديد الملف * * param FullPath * @REGARN * / private Static String [] extensions (String FullPath) {string [] extension = {} ؛ حاول {file file = ملف جديد (FullPath) ؛ الامتدادات (ملف) ؛ } catch (استثناء ex) {j2log (null ، null ، ex) ؛ } تمديد الإرجاع ؛ } / ** * امتدادات الحصول على معلومات تمديد الملف * * param file * @return * / private static string [] extensions (file file) {string [] extension = {} ؛ حاول {if (file.isfile ()) {string filename = file.getName () ؛ if (filename.lastindexof (".")> = 0) {int lastIndex = filename.lastindexof (".") ؛ الامتداد [0] = string.valueof (lastIndex) ؛ // index of "." الامتداد [1] = filename.substring (LastIndex + 1) ؛ // تمديد التمديد [2] = filename.substring (0 ، lastIndex) ؛ // file name}}} catch (استثناء ex) {j2log (null ، null ، ex) ؛ } تمديد الإرجاع ؛ } / ** * ls اجتياز الملف * * param filepath * param loop * @return * / قائمة ثابتة عامة <file> ls (سلسلة filepath ، حلقة Boolean) {list <file> list = new ArrayList () ؛ حاول {file file = ملف جديد (FilePath) ؛ list.addall (ls (ملف ، حلقة)) ؛ } catch (استثناء ex) {j2log (null ، null ، ex) ؛ } قائمة الإرجاع ؛ } / ** * ls اجتياز الملف * * param file * param loop * @REGANT * / قائمة ثابتة عامة <file> ls (ملف الملف ، حلقة منطقية) {list <ible> list = new ArrayList () ؛ حاول {list.add (file) ؛ if (! file.isdirectory ()) {list.add (file) ؛ } آخر if (file.isDirectory ()) {file [] sublist = file.listfiles () ؛ ساوفي المحرك = fileStort (قائم فرعي ، صحيح) ؛ for (file subfile: sublist) {if (subfile.isdirectory () && loop) {list.addall (ls (subfile.getPath () ، loop)) ؛ } آخر {list.add (subfile) ؛ }}}} catch (استثناء ex) {j2log (null ، null ، ex) ؛ } قائمة الإرجاع ؛ } / ** * FileStort File Sort (Order Wordence Implor) * * param ParentPath * param sublist * @return * / private static file [] filessort (file [] infiles ، boolean asc) {list <string> files = new ArrayList () ؛ قائمة <Tring> dirs = new ArrayList () ؛ for (file subfile: infiles) {if (subfile.isdirectory ()) {dirs.add (subfile.getPath ()) ؛ } آخر if (subfile.ispile ()) {files.add (subfile.getPath ()) ؛ }} string [] fileArray = {} ؛ if (files.size ()> 0) {filearRay = list2array (files) ؛ المصفوفات. if (! asc) {arrays.sort (filearray ، collections.reverseorder ()) ؛ }} string [] dirarray = {} ؛ if (dirs.size ()> 0) {dirArray = list2array (dirs) ؛ المصفوفات. if (! asc) {arrays.sort (dirarray ، collections.reverseorder ()) ؛ }} return concat2fiLearray (filearray ، dirarray) ؛ } / ** * concat2fiLearray دمج ملف * * param old1 * param old2 * @regurn * / private static file [] concat2fiLearray (string [] old1 ، string [] old2) {file [] newarray = new file [old1.length + old2.length] ؛ لـ (int i = 0 ، n = old1.length ؛ i <n ؛ i ++) {newarray [i] = new file (old1 [i]) ؛ } لـ (int i = 0 ، j = old1.length ، n = (old1.length+old2.length) ؛ j <n ؛ i ++ ، j ++) {newarray [j] = file new (old2 [i]) ؛ } إرجاع نياراي ؛ } / ** * اقرأ قراءة الملف النص * * param filepath * param filename * param charset * return * / public static stringbuilder read (String filepath ، string fileName ، string charset) {StringBuilder sb = new StringBuilder () ؛ حاول {String FullPath = CombatePath (FilePath ، filename) ؛ ملف الملف = ملف جديد (FullPath) ؛ sb.append (fileTools.loy (ملف ، خطأ ، 0 ، charset)) ؛ } catch (استثناء ex) {j2log (null ، null ، ex) ؛ } إرجاع sb ؛ } / ** * اقرأ قراءة الملف النص * * param fullpath * param charset * @return * / public static stringbuilder read (String FullPath ، string charset) {StringBuilder sb = new StringBuilder () ؛ حاول {file file = ملف جديد (FullPath) ؛ sb.append (fileTools.loy (ملف ، خطأ ، 0 ، charset)) ؛ } catch (استثناء ex) {j2log (null ، null ، ex) ؛ } إرجاع sb ؛ } / ** * اقرأ قراءة الملف النصي * * param file * param charset * @RETURN * / public static stringbuilder read (file file ، string charset) {StringBuilder sb = new StringBuilder () ؛ حاول {sb.append (fileTools.loy (ملف ، خطأ ، 0 ، charset)) ؛ } catch (استثناء ex) {j2log (null ، null ، ex) ؛ } إرجاع sb ؛ } / ** * ابحث عن السطر المحدد للملف النصي * * 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 () ؛ حاول {String FullPath = CombatePath (FilePath ، filename) ؛ ملف الملف = ملف جديد (FullPath) ؛ sb.append (fileTools.loy (ملف ، صواب ، سطر ، charset)) ؛ } catch (استثناء ex) {j2log (null ، null ، ex) ؛ } إرجاع sb ؛ } / ** * ابحث عن السطر المحدد للملف النصي * * param fullpath * param line * param charset * @REGURN * / public static stringbuilder find (String fullpath ، int charset) {StringBuilder sb = new StringBuilder () ؛ حاول {file file = ملف جديد (FullPath) ؛ sb.append (fileTools.loy (ملف ، صواب ، سطر ، charset)) ؛ } catch (استثناء ex) {j2log (null ، null ، ex) ؛ } إرجاع sb ؛ } / ** * ابحث عن السطر المحدد للملف النصي * * param file * @param line * param charset * @return * / public static stringbuilder find (file file ، int line ، string charset) {StringBuilder sb = new StringBuilder () ؛ حاول {sb.append (fileTools.aild (ملف ، صواب ، سطر ، charset)) ؛ } catch (استثناء ex) {j2log (null ، null ، ex) ؛ } إرجاع sb ؛ } / ** * tail اقرأ الملف النصي * * param filepath * param filename * param charset * param find * @param line * @regring static stringbuilder tail (String filepath ، string filename ، boolean find ، int line ، string charset) حاول {String FullPath = CombatePath (FilePath ، filename) ؛ ملف الملف = ملف جديد (FullPath) ؛ sb.append (filetools.tail (file ، find ، line ، charset)) ؛ } catch (استثناء ex) {j2log (null ، null ، ex) ؛ } إرجاع sb ؛ } / ** * tail read file file * * param fullpath * param charset * param find * param line * @return * / public Static StringBuilder tail (String fullpath ، boolean find ، int line ، string charset) {StringBuilder sb = new StringBuilder () ؛ حاول {file file = ملف جديد (FullPath) ؛ sb.append (filetools.tail (file ، find ، line ، charset)) ؛ } catch (استثناء ex) {j2log (null ، null ، ex) ؛ } إرجاع sb ؛ } / ** * tail read file file * * param file * param charset * param find * param line * @return * / public static stringbuilder tail (ملف الملف ، العثور على السطر المنطقي ، int charset) {StringBuilder sb = new StringBuilder () ؛ BufferedReader Bufferreader = null ؛ if (null == charset || "" .equals (charset)) {charset = "utf-8" ؛ } جرب {if (! file.exists () || file.isdirectory ()) {throw fileNotfoundException () ؛ } String FullPath = file.getPath () ؛ BufferReader = جديد BufferedReader (inputStreamReader جديد (FileInputStream جديد (FullPath) ، Charset)) ؛ سلسلة درجة الحرارة ؛ لـ (int i = 0 ؛ (temp = bufferreader.readline ())! = null ؛ i ++) {if (! find || line == i) {sb.append (temp) ؛ }}} catch (استثناء ex) {j2log (null ، null ، ex) ؛ } أخيرًا {if (null! = bufferreader) {try {bufferreader.close () ؛ } catch (ioException ex) {j2log (null ، null ، ex) ؛ }}} return sb ؛ } / ** * SED اقرأ ملف نصي * * param filepath * param filename * param charset * @return * / public static list <string> sed (سلسلة filepath ، اسم ملف السلسلة ، charset) {list <string> list = new ArrayList () ؛ حاول {String FullPath = CombatePath (FilePath ، filename) ؛ ملف الملف = ملف جديد (FullPath) ؛ list.addall (filetools.sed (ملف ، charset)) ؛ } catch (استثناء ex) {j2log (null ، null ، ex) ؛ } قائمة الإرجاع ؛ } / ** * sed قراءة ملف نصي * * param fullpath * param charset * return * / قائمة ثابتة عامة <string> sed (String fullPath ، String charset) {list <string> list = new ArrayList () ؛ حاول {file file = ملف جديد (FullPath) ؛ list.addall (filetools.sed (ملف ، charset)) ؛ } catch (استثناء ex) {j2log (null ، null ، ex) ؛ } قائمة الإرجاع ؛ } / ** * sed قراءة ملف نصي * * param file * param charset * return * / قائمة ثابتة عامة <string> sed (ملف الملف ، سلسلة charset) {list <string> list = new ArrayList () ؛ BufferedReader Bufferreader = null ؛ if (null == charset || "" .equals (charset)) {charset = "utf-8" ؛ } جرب {if (! file.exists () || file.isdirectory ()) {throw fileNotfoundException () ؛ } String FullPath = file.getPath () ؛ BufferReader = جديد BufferedReader (inputStreamReader جديد (FileInputStream جديد (FullPath) ، Charset)) ؛ سلسلة درجة الحرارة ؛ لـ (int i = 0 ؛ (temp = bufferreader.readline ())! = null ؛ i ++) {list.add (temp) ؛ }} catch (استثناء ex) {j2log (null ، null ، ex) ؛ } أخيرًا {if (null! = bufferreader) {try {bufferreader.close () ؛ } catch (ioException ex) {j2log (null ، null ، ex) ؛ }}} قائمة الإرجاع ؛ } / ** * Cat قراءة الملف النص * * param filepath * param filename * @REGTURN * / public static byte [] cat (String filepath ، string fileName) {byte [] output = {} ؛ حاول {String FullPath = CombatePath (FilePath ، filename) ؛ ملف الملف = ملف جديد (FullPath) ؛ الإخراج = fileTools.cat (ملف) ؛ } catch (استثناء ex) {j2log (null ، null ، ex) ؛ } إخراج الإرجاع ؛ } / ** * cat قراءة ملف النص * * param fullpath * return * / public static byte [] cat (String fullPath) {byte [] output = {} ؛ حاول {file file = ملف جديد (FullPath) ؛ الإخراج = fileTools.cat (ملف) ؛ } catch (استثناء ex) {j2log (null ، null ، ex) ؛ } إخراج الإرجاع ؛ } / ** * cat قراءة ملف النص * * param file * return * / public static byte [] cat (file file) {inputStream in = null ؛ byte [] output = {} ؛ حاول {if (! file.exists () || file.isdirectory ()) {رمي fileNotFoundException () ؛ } String FullPath = file.getPath () ؛ طول طويل = du (ملف ، خطأ) ؛ طويل _2m = 2097152 ؛ Byte [] bytes = new byte [(int) length] ؛ في = جديد fileInputStream (FullPath) ؛ لـ (int count = 0 ؛ count! = -1 ؛) {if (length> 16 * _2m) {length = 4 * _2m ؛ } آخر إذا (الطول> 8 * _2M) {length = 2 * _2m ؛ } آخر إذا (الطول> 4 * _2M) {length = _2m ؛ } آخر إذا (الطول> 2 * _2M) {length = _2m / 2 ؛ } آخر إذا (طول> _2m) {length = _2m / 4 ؛ } آخر {length = 4096 ؛ } bytes = new byte [(int) length] ؛ count = in.read (bytes) ؛ الإخراج = concatarray (بايت ، الإخراج) ؛ الطول = in.available () ؛ }} catch (استثناء ex) {j2log (null ، null ، ex) ؛ } أخيرًا {if (null! = in) {try {in.close () ؛ } catch (استثناء ex) {j2log (null ، null ، ex) ؛ }}} إخراج الإرجاع ؛ } / ** * دمج صفيف * * param old1 * param old2 * @return * / private static byte [] concatarray (byte [] old1 ، byte [] old2) {byte [] newArray = new byte [old1.length + old2.length] ؛ System.ArrayCopy (Old1 ، 0 ، Newarray ، 0 ، Old1.Length) ؛ System.arrayCopy (Old2 ، 0 ، Newarray ، Old1.Length ، Old2.length) ؛ إرجاع نياراي } / ** * dd crite fullpath content content * * param filepath * param filename * param content * param isAppend * / public static void dd (String filepath ، string filename ، byte [] content ، boolean isAppend) {try {string fullpath = combinePath (filepath ، filename) ؛ ملف الملف = ملف جديد (FullPath) ؛ fileTools.dd (ملف ، محتوى ، isAppend) ؛ } catch (استثناء ex) {j2log (null ، null ، ex) ؛ }} / ** * dd write fullpath content content * * param fullpath * param content * param isAppend * / public static void dd (String fullpath ، byte [] content ، boolean iSappend) {try {file file = new file (fullpath) ؛ fileTools.dd (ملف ، محتوى ، isAppend) ؛ } catch (استثناء ex) {j2log (null ، null ، ex) ؛ }} / ** * dd crite fullpath content content * * param file * param content * param isAppend * / public static void dd (ملف ملف ، byte [] المحتوى ، boolean isAppend) {fileOutputStream fileOutputStream = null ؛ حاول {if (! file.exists ()) {file.createNewFile () ؛ } fileOutputStream = جديد fileOutputStream (ملف ، isAppend) ؛ fileOutputStream.write (content) ؛ } catch (استثناء ex) {j2log (null ، null ، ex) ؛ } أخيرًا {try {if (null! = fileOutputStream) {fileOutputStream.close () ؛ }} catch (ioException ex) {j2log (null ، null ، ex) ؛ }}}} / ** * اكتب محتوى كتابة ملف إلى ملف FullPath * * param filepath * param filename * param content * / public static void write (string filepath ، string filenment ، string content) {try {string fullpath = combinePath (filepath ، filename) ؛ ملف الملف = ملف جديد (FullPath) ؛ filetools.write (ملف ، محتوى ، صحيح) ؛ } catch (استثناء ex) {j2log (null ، null ، ex) ؛ }} / ** * اكتب محتوى ملف كتابة ملف FullPath * * param fullpath * param content * / public static void write (String fullPath ، string content) {try {file file = new file (fullpath) ؛ filetools.write (ملف ، محتوى ، صحيح) ؛ } catch (استثناء ex) {j2log (null ، null ، ex) ؛ }} / ** * اكتب محتوى كتابة ملف إلى ملف FullPath * * param file * param content * / public static void write (ملف الملف ، محتوى السلسلة) {try {filetools.write (ملف ، محتوى ، صحيح) ؛ } catch (استثناء ex) {j2log (null ، null ، ex) ؛ }} / ** * اكتب اكتب (إلحاق) محتوى الملف إلى ملف FullPath * * param filepath * param filename * param content * param isAppend * / public static void write (String filepath ، filename ، string content ، boolean isAppend) {try {String fullpath = combinePath (filepath ، filename) ؛ ملف الملف = ملف جديد (FullPath) ؛ filetools.write (ملف ، محتوى ، isAppend) ؛ } catch (استثناء ex) {j2log (null ، null ، ex) ؛ }} / ** * اكتب اكتب (إلحاح) محتوى الملف إلى ملف FullPath * * param fullpath * param content * param isAppend * / public static void write (String fullpath ، string content ، boolean iSappend) {try {file file = new file (fullpath) ؛ filetools.write (ملف ، محتوى ، isAppend) ؛ } catch (استثناء ex) {j2log (null ، null ، ex) ؛ }} / ** * اكتب كتابة (إلحاق) محتوى الملف إلى ملف FullPath * * param file * param content * param isAppend * / public static void write (ملف ، محتوى السلسلة ، iSappend) {fileWriter filewriter = null ؛ حاول {if (! file.exists ()) {file.createNewFile () ؛ } filewRiter = new filewRiter (file.getPath () ، isAppend) ؛ filewriter.write (المحتوى) ؛ } catch (استثناء ex) {j2log (null ، null ، ex) ؛ } أخيرًا {if (null! = filewRiter) {try {fileWriter.close () ؛ } catch (ioException ex) {j2log (null ، null ، ex) ؛ }}}}} / ** * إضافة محتوى الملف محتوى الملف إلى موقع الفهرس للملف * * param filepath * param filename * param content * @param index * / public static void tail (سلسلة FilePath ، filename ، محتوى السلسلة ، فهرس طويل) ملف الملف = ملف جديد (FullPath) ؛ fileTools.aild (ملف ، محتوى ، فهرس) ؛ } catch (استثناء ex) {j2log (null ، null ، ex) ؛ }} / ** * إضافة محتوى محتوى الملف إلى موقع فهرس الملف * * param fullpath * param content * param index * / public static void tail (سلسلة FullPath ، محتوى السلسلة ، الفهرس الطويل) {try {file file = fullpath) ؛ fileTools.aild (ملف ، محتوى ، فهرس) ؛ } catch (استثناء ex) {j2log (null ، null ، ex) ؛ }} / ** * إضافة محتوى محتوى الملف إلى موقع فهرس الملف * * param file * param content * param index * / public static void tail (ملف الملف ، محتوى السلسلة ، الفهرس الطويل) {randomaccessfile randomaccessfile = null ؛ حاول {if (! file.exists ()) {file.createNewFile () ؛ } randomaccessfile = new RandomAccessFile (file.getPath () ، "rw") ؛ randomaccessfile.keek (index) ؛ randomaccessfile.writeBytes (المحتوى) ؛ } catch (استثناء ex) {j2log (null ، null ، ex) ؛ } أخيرًا {if (null! = randomaccessfile) {try {randomaccessfile.close () ؛ } catch (استثناء ex) {j2log (null ، null ، ex) ؛ }}}}} / ** * MKDIR إنشاء دليل * * param filepath * param filename * @RETURN * / public static file MKDIR (String filepath ، string filename) {file file = null ؛ حاول {String FullPath = CombatePath (FilePath ، filename) ؛ ملف = ملف جديد (FullPath) ؛ ملف = mkdir (ملف) ؛ } catch (استثناء ex) {j2log (null ، null ، ex) ؛ } ملف الإرجاع ؛ } / ** * MKDIR إنشاء دليل * * param fullpath * @return * / public static file mkdir (String fullPath) {file file = null ؛ حاول {file = ملف جديد (FullPath) ؛ ملف = mkdir (ملف) ؛ } catch (استثناء ex) {j2log (null ، null ، ex) ؛ } ملف الإرجاع ؛ }/** * mkdir إنشاء دليل * * param file * regurn */public static file mkdir (ملف ملف) {try {if (! file.exists ()) {file.mkdir () ؛ // إنشاء إذا لم يكن المجلد موجودًا}} } ملف الإرجاع ؛ } / ** * touch create file * * param filepath * param filename * / public static void touch (String filepath ، string filename) {try {String fullPath = combinePath (filepath ، filename) ؛ ملف الملف = ملف جديد (FullPath) ؛ اللمس (ملف) ؛ } catch (استثناء ex) {j2log (null ، null ، ex) ؛ }} / ** * touch create file * * param fullpath * / public static void touch (String fullPath) {try {file file = new file (fullPath) ؛ اللمس (ملف) ؛ } catch (استثناء ex) {j2log (null ، null ، ex) ؛ }}/** * touch create file * * param file */public static void touch (file file) {try {if (! file.exists ()) {file.createNewFile () ؛ // إنشاء إذا لم يكن الملف موجودًا}} catch (استثناء ex) {j2log (null ، null ، ex) ؛ }} / ** * RM حذف الملف * * param filepath * param filename * / public static void rm (سلسلة filepath ، اسم ملف السلسلة) {try {string fullpath = combinePath (filepath ، filename) ؛ ملف الملف = ملف جديد (FullPath) ؛ RM (ملف) ؛ } catch (استثناء ex) {j2log (null ، null ، ex) ؛ }} / ** * rm delete file * * param fullpath * / public static void rm (String fullPath) {try {file file = new file (fullPath) ؛ RM (ملف) ؛ } catch (استثناء ex) {j2log (null ، null ، ex) ؛ }} / ** * rm delete file * * param file * / public static void rm (file file) {try {if (! file.exists ()) {throw fileNotfoundException () ؛ } if (file.isfile ()) {file.delete () ؛ }} catch (استثناء ex) {j2log (null ، null ، ex) ؛ }} / ** * RMDIR DELETE DIRENTORY * * param filepath * param filename * param loop * / public static void rmdir (سلسلة filepath ، اسم ملف السلسلة ، حلقة boolean) {try {String fullPath = combinePath (filepath ، filepath) ؛ ملف dir = ملف جديد (FullPath) ؛ rmdir (dir ، loop) ؛ } catch (استثناء ex) {j2log (null ، null ، ex) ؛ }} / ** * RMDIR DELETE DIRENTORY * * param fullpath * param loop * / public static void rmdir (String fullpath ، boolean loop) {try {file dir = new file (fullpath) ؛ rmdir (dir ، loop) ؛ } catch (استثناء ex) {j2log (null ، null ، ex) ؛ }} / ** * RMDIR DELETE DIRENTORY * * param dir * param loop * / public static void rmdir (file dir ، loop boolean) {try {if (! } if (dir.isdirectory ()) {file [] files = dir.listfiles () ؛ طول int = files.length ؛ لـ (int i = 0 ؛ i <length && loop ؛ i ++) {if (files [i] .isdirectory ()) {rmdir (files [i] ، loop) ؛ } آخر {rm (ملفات [i]) ؛ }} if (loop || length == 0) {dir.delete () ؛ }}} catch (استثناء ex) {j2log (null ، null ، ex) ؛ }} / ** * du احصل على حجم الملف الفعلي * * param filepath * param filename * param loop * return * / public static long du (سلسلة filepath ، اسم ملف السلسلة ، حلقة boolean) {long size = 0 ؛ حاول {String FullPath = CombatePath (FilePath ، filename) ؛ ملف الملف = ملف جديد (FullPath) ؛ الحجم = du (ملف ، حلقة) ؛ } catch (استثناء ex) {j2log (null ، null ، ex) ؛ } حجم الإرجاع ؛ } / ** * du احصل على حجم الملف الفعلي * * param filepath * param filename * @return * / public static du (سلسلة filepath ، اسم ملف السلسلة) {long size = 0 ؛ حاول {String FullPath = CombatePath (FilePath ، filename) ؛ ملف الملف = ملف جديد (FullPath) ؛ الحجم = du (ملف ، خطأ) ؛ } catch (استثناء ex) {j2log (null ، null ، ex) ؛ } حجم الإرجاع ؛ } / ** * du احصل على حجم الملف الفعلي * * param fullpath * @return * / public static du (string fullpath) {long size = 0 ؛ حاول {file file = ملف جديد (FullPath) ؛ الحجم = du (ملف ، خطأ) ؛ } catch (استثناء ex) {j2log (null ، null ، ex) ؛ } حجم الإرجاع ؛ } / ** * du احصل على حجم الملف الفعلي * * param file * @return * / public static long du (file file) {long size = 0 ؛ حاول {size = du (ملف ، false) ؛ } catch (استثناء ex) {j2log (null ، null ، ex) ؛ } حجم الإرجاع ؛ } / ** * du احصل على حجم الملف الفعلي * * param fullpath * param loop * @return * / public static du (String fullpath ، loop boolean) {long size = 0 ؛ حاول {file file = ملف جديد (FullPath) ؛ الحجم = du (ملف ، حلقة) ؛ } catch (استثناء ex) {j2log (null ، null ، ex) ؛ } حجم الإرجاع ؛ } / ** * du احصل على حجم الملف الفعلي * * param file * param loop * @regurn * / public static long du (ملف ملف ، حلقة منطقية) {fileChannel filechannel = null ؛ حجم طويل = 0 ؛ جرب {if (! file.exists ()) {رمي fileNotFoundException () ؛ } if (file.isfile ()) {fileInputStream fis = new FileInputStream (file) ؛ filechannel = fis.getChannel () ؛ الحجم = filechannel.size () ؛ } آخر if (file.isDirectory ()) {file [] files = file.listfiles () ؛ طول int = files.length ؛ لـ (int i = 0 ؛ i <length && loop ؛ i ++) {if (files [i] .isdirectory ()) {du (files [i] ، loop) ؛ } آخر {size += du (files [i] ، false) ؛ }}}} catch (استثناء ex) {j2log (null ، null ، ex) ؛ } أخيرًا {if (null! = filechannel) {try {filechannel.close () ؛ } catch (استثناء ex) {j2log (null ، null ، ex) ؛ }}} حجم الإرجاع ؛ }}ما سبق هو كل شيء عن هذا المقال ، آمل أن يكون مفيدًا لتعلم الجميع.