최근에, 좋아하는 미국 드라마의 파일 이름을 수정하기 위해 스윙을 사용하여 위젯을 썼습니다. 코드는 파일 처리 부분입니다. 특정 내용은 다음과 같습니다
패키지 datei.steuern; import java.io.bufferedReader; import java.io.file; import java.io.fileInputStream; import java.io.filenotFoundException; import java.io.fileoutputStream; import java.io.filewriter; import java.io.io.io.inputStreameder; java.io.randomaccessfile; import java.nio.bytebuffer; import java.nio.channels.filechannel; import java.util.arraylist; import java.util.arrays; import java.util.collections; import java.util.list; import java.util.logging java.util.logging.logger; /** * * @author s.watson */public class filetools {public filetools () {}/** * FormatPath Escape 파일 디렉토리 * * @param path * @return */public static string formatpath (String Path) {return path.replaceall ( "//", "); } / ** * 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 ( "//", "/"); } 반환 도리; } / ** * List2ARRAY LIST 변환 배열 * * @Param List * @return * / private static string [] list2Array (목록) {String array [] = (string []) list.toArray (새 문자열 [list.size ()]; 반환 배열; } / ** * CP 사본 파일 * * @param 소스 * @param 대상 * @param loop * @return * / public static list <file> cp (문자열 소스, 문자열 대상, 부울 루프) {list <file> list = new arrayList (); try {file srcfile = 새 파일 (source); 파일 desfile = 새 파일 (대상); list.addall (cp (srcfile, desfile, loop)); } catch (Exception Ex) {j2Log (null, null, ex); } 반환 목록; } / ** * CP 사본 파일 * * @param 소스 * @param 대상 * @param loop * @return * / public static list <file> cp (파일 소스, 파일 대상, 부울 루프) {list <file> list = new arrayList (); try {if (! source.exists () || source.isdirectory ()) {wrach new filenotfoundException (); } list.add (cp (소스, 대상)); if (loop) {string [] subfile = source.list (); for (string subpath : subfile) {string src = combinePath (source.getPath (), subpath); // 서브 파일 string des = combinePath (destination.getPath (), subpath)의 원본 파일 경로; // 하위 파일 서브 파일의 대상 경로 = 새 파일 (src); if (subfile.isfile ()) {list.add (cp (src, des)); } else if (subfile.isdirectory () && loop) {list.addall (cp (src, des, loop)); }}}}} catch (예외 예외) {j2log (null, null, ex); } 반환 목록; } / ** * CP 단일 파일 복사 파일 * * @Param 소스 * @Param 대상 * @return * / public static file cp (문자열 소스, 문자열 대상) {file desfile = null; try {file srcfile = 새 파일 (source); desfile = 새 파일 (대상); desfile = cp (srcfile, desfile); } catch (Exception Ex) {j2Log (null, null, ex); } return desfile; } / ** * CP 단일 파일 복사 파일 * * @param 소스 * @param 대상 * @return * / public static file cp (파일 소스, 파일 대상) {fileInputStream in = null; fileoutputStream out = null; filechannel inc = null; filechannel outc = null; try {if (! source.exists () || source.isdirectory ()) {wrach new filenotfoundException (); } if (source.getPath (). Equals (대상 .getPath ())) {return source; } long allbytes = du (source, false); if (! destination.exists ()) {destination.createnewfile (); } in = new FileInputStream (source.getPath ()); out = new FileOutputStream (대상); inc = in.getChannel (); outc = out.getChannel (); 바이트 버퍼 바이트 버퍼 = null; 긴 길이 = 2097152; // 기본 크기, 기본 2m 길이 _2m = 2097152; while (inc.position () <inc.size ()) {if (allbytes> (64 * length))) {// 파일 크기가 128m보다 큰 경우 캐시는 64m 길이 = 32 * _2m으로 변경됩니다. } else if (allbytes> (32 * length)) {// 파일 크기가 64m보다 큰 경우 캐시는 32m 길이 = 16 * _2m으로 변경됩니다. } else if (allbytes> (16 * length)) {// 파일 크기가 32m보다 큰 경우 캐시는 16m 길이 = 8 * _2m으로 변경됩니다. } else if (allbytes> (8 * length)) {// 파일 크기가 16m보다 큰 경우 캐시는 8m 길이 = 4 * _2m으로 변경됩니다. } else if (allbytes> (4 * length)) {// 파일 크기가 8m보다 큰 경우 캐시는 4m 길이 = 2 * _2m으로 변경됩니다. } else if (allbytes> (2 * length)) {// 파일 크기가 4m보다 큰 경우 캐시는 2m 길이 = _2m으로 변경됩니다. } else if (allbytes> (length)) {// 파일 크기가 2m보다 큰 경우 캐시는 1m 길이 = _2m/2로 변경됩니다. } else if (Allbytes <length) {// 파일이 기본 크기보다 작은 경우 출력 길이 직접 = Allbytes; } allbytes = inc.size () - Inc.Position (); 바이트 버퍼 = bytebuffer.allocatedirect ((int) 길이); inc.read (바이 테 버퍼); Bytebuffer.flip (); outc.write (Bytebuffer); outc.force (false); }} catch (예외 예) {j2log (null, null, ex); } 마침내 {try {if (null! = inc) {inc.close (); } if (ull! = outc) {outc.close (); } if (ull! = in) {in.close (); } if (ull! = out) {out.close (); }} catch (예외 예) {j2log (null, null, ex); }} 반환 목적지; } / ** * 파일 이름 이름 바꾸기 * * @param filepath * @param from * @param to * @return * / public static 파일 이름 (문자열 filepath, string from, string to) {file newfile = null; try {file OldFile = 새 파일 (CombainPath (filepath, from)); NewFile = 새 파일 (CombainPath (Filepath, to)); 이름 바꾸기 (NewFile, OldFile); } catch (Exception Ex) {j2Log (null, null, ex); } return newFile; } / ** * 파일 이름 이름 바꾸기 * * @param to * @param from * @return * / public static 파일 이름 (파일에서 파일, 파일 to) {try {string {string {string newPath = to.getPath (); String OldPath = from.getPath (); if (! OldPath.equals (newPath)) {if (! to.exists ()) {from.renameto (to); }}} catch (예외 예) {j2log (null, null, ex); }로 돌아갑니다. } / ** * MV 이동 파일 * * @param filename * @param source * @param 대상 * @param cover * / public static void mv (문자열 파일 이름, 문자열 소스, 문자열 대상, 부울 커버) {try (! source.equals (대상)) {file oldfile = 새 파일 (combainpath (source, filename)); file newFile = 새 파일 (CombainPath (대상, 파일 이름)); MV (Oldfile, Newfile, Cover); }} catch (예외 예) {j2log (null, null, ex); }} / ** * mv 이동 파일 * * @param 소스 * @param 대상 * @param cover * / public static void mv (문자열 소스, 문자열 대상, 부울 커버) {try {if (! source.equals (대상)) {file oldfile = new File (source); file newFile = 새 파일 (대상); MV (Oldfile, Newfile, Cover); }} catch (예외 예) {j2log (null, null, ex); }} / ** * mv 이동 파일 * * @param 소스 * @param 대상 * @param cover * / public static void mv (파일 소스, 파일 대상, 부울 커버) {try {if (! source.exists ()) {strach new filenotfoundException (); } stringBuilder filename = new StringBuilder (source.getName ()); if (! cover && source.getpath (). equals (stured.getPath ())) {if (filename.indexof ( ".")> 0) {filename.insert (filename.lastIndexof ( "),"_copy "); } else {filename.append ( "_ copy"); } cp (source, new File (combainPath (source.getParent (), filename.toString ())); } else {source.renameto (대상); }} catch (예외 예) {j2log (null, null, ex); }} / ** * 확장자는 파일 확장 정보를 가져옵니다 * @param filepath * @param filename * @return * / private static string [] extensions (String filepath, String filename) {String [] extension = {}; try {String fullPath = CombinePath (filepath, filename); 파일 = 새 파일 (fullPath); 확장 (파일); } catch (Exception Ex) {j2Log (null, null, ex); } 리턴 확장; } / ** * 확장자가 파일 확장 정보를 가져옵니다 * @param fullpath * @return * / private static string [] extensions (String fullPath) {String [] extension = {}; try {file file = new File (fullPath); 확장 (파일); } catch (Exception Ex) {j2Log (null, null, ex); } 리턴 확장; } / ** * 확장자 파일 확장 정보를 가져옵니다 * @param 파일 * @return * / private static string [] extensions (파일 파일) {String [] extension = {}; try {if (file.isfile ()) {String filename = file.getName (); if (filename.lastIndexof ( ".")> = 0) {int lastIndex = filename.lastIndexof ( "."); Extension [0] = string.valueof (lastIndex); // 색인 "." Extension [1] = filename.substring (lastIndex + 1); // Extension Extension [2] = filename.subString (0, lastIndex); // file name}}} catch (예외 Ex) {j2log (null, null, ex); } 리턴 확장; } / ** * ls 파일을 가로 지르는 * * @param filepath * @param loop * @return * / public static list <file> ls (문자열 FilePath, 부울 루프) {list <file> list = new arrayList (); try {file file = new File (FilePath); list.addall (ls (파일, 루프)); } catch (Exception Ex) {j2Log (null, null, ex); } 반환 목록; } / ** * ls 파일을 가로 지르는 * * @param 파일 * @param loop * @return * / public static list <file> ls (파일 파일, 부울 루프) {list <file> list = new arrayList (); try {list.add (파일); if (! file.isdirectory ()) {list.add (file); } else if (file.isdirectory ()) {file [] sublist = file.listfiles (); Subrist = filessort (Subrist, True); for (file subfile : sublist) {if (subfile.isdirectory () && loop) {list.addall (ls (subfile.getPath (), loop); } else {list.add (subfile); }}}} catch (예외 예외) {j2log (null, null, ex); } 반환 목록; } / ** * filessort 파일 정렬 (기본 오름차순) * * @param parentpath * @param sublist * @return * / private static file [] filessort (file [] infiles, boolean asc) {list <string> files = new arraylist (); list <string> dirs = new ArrayList (); for (file subfile : infiles) {if (subfile.isdirectory ()) {dirs.add (subfile.getPath ()); } else if (subfile.isfile ()) {files.add (subfile.getPath ()); }} string [] filearray = {}; if (files.size ()> 0) {filearray = list2array (files); 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 cocat2filearray (filearray, dirarray); } / ** * concat2filearray는 파일 배열을 병합합니다 * @param old1 * @param old2 * @return * / private static file [] concat2filearray (string [] Old1, String [] Old2) {file [] newArray = new File [Old1.length + Old2.length]; for (int i = 0, n = old1.length; i <n; i ++) {newArray [i] = 새 파일 (Old1 [i]); } for (int i = 0, j = old1.length, n = (Old1.length+Old2.length); j <n; i ++, j ++) {newArray [j] = 새 파일 (Old2 [i]); } return newArray; } / ** * 읽기 텍스트 파일 읽기 * * @param filepath * @param filename * @param charset * @return * / public static stringbuilder read (문자열 filepath, 문자열 파일 이름, 문자열 charset) {StringBuilder sb = new StringBuilder (); try {String fullPath = CombinePath (filepath, filename); 파일 = 새 파일 (fullPath); sb.append (filetools. tail (file, false, 0, charset)); } catch (Exception Ex) {j2Log (null, null, ex); } 반환 sb; } / ** * 읽기 텍스트 파일 읽기 * * @param fullpath * @param charset * @return * / public static stringbuilder read (String fullPath, String charset) {StringBuilder sb = new StringBuilder (); try {file file = new File (fullPath); sb.append (filetools. tail (file, false, 0, charset)); } catch (Exception Ex) {j2Log (null, null, ex); } 반환 sb; } / ** * 읽기 텍스트 파일 읽기 * * @param 파일 * @param charset * @return * / public static stringbuilder read (파일 파일, 문자열 charset) {StringBuilder sb = new StringBuilder (); try {sb.append (filetools. tail (file, false, 0, charset)); } catch (Exception Ex) {j2Log (null, null, ex); } 반환 sb; } / ** * 찾기 텍스트 파일의 지정된 줄을 읽습니다 * @param filepath * @param filename * @param charset * @return * / public static stringbuilder find (문자열 filepath, 문자열 파일 이름, int line, String charset) {StringBuilder sb = new StringBuilder (); try {String fullPath = CombinePath (filepath, filename); 파일 = 새 파일 (fullPath); sb.append (filetools. tail (file, true, line, charset)); } catch (Exception Ex) {j2Log (null, null, ex); } 반환 sb; } / ** * 텍스트 파일의 지정된 줄을 읽습니다 * @param fullpath * @param line * @param charset * @return * / public static stringbuilder 찾기 (String fullpath, int line, string charset) {StringBuilder sb = new StringBuilder (); try {file file = new File (fullPath); sb.append (filetools. tail (file, true, line, charset)); } catch (Exception Ex) {j2Log (null, null, ex); } 반환 sb; } / ** * 텍스트 파일의 지정된 줄을 읽습니다 * @param file * @param line * @param charset * @return * / public static stringbuilder 찾기 (파일 파일, int 줄, 문자열 charset) {StringBuilder sb = new StringBuilder (); try {sb.append (filetools. tail (file, true, line, charset)); } catch (Exception Ex) {j2Log (null, null, ex); } 반환 sb; } / ** * 테일 텍스트 파일 읽기 * * @param filepath * @param filename * @param charset * @param find * @param line * @return * / public static stringbuilder tail (문자열 filepath, String filename, int line, Stringbuilder sb = new StringBuilder (); try {String fullPath = CombinePath (filepath, filename); 파일 = 새 파일 (fullPath); sb.append (filetools. tail (file, find, line, charset)); } catch (Exception Ex) {j2Log (null, null, ex); } 반환 sb; } / ** * 꼬리 읽기 텍스트 파일 * * @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 (); try {file file = new File (fullPath); sb.append (filetools. tail (file, find, line, charset)); } catch (Exception Ex) {j2Log (null, null, ex); } 반환 sb; } / ** * 꼬리 읽기 텍스트 파일 * * @param 파일 * @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"; } try {if (! file.exists () || file.isdirectory ()) {새 filenotfoundException (); } string fullPath = file.getPath (); bufferReader = new bufferedReader (new inputStreamReader (new FileInputStream (fullPath), charset); 문자열 온도; for (int i = 0; }}} catch (예외 예) {j2log (null, null, ex); } 마침내 {if (null! = BuffErreader) {try {buffErreader.close (); } catch (ioexception ex) {j2log (null, null, ex); }}} 반환 sb; } / ** * sed 텍스트 파일 읽기 * * @param filepath * @param filename * @param charset * / public static list <string> sed (문자열 filepath, 문자열 파일 이름, 문자열 charset) {list <string> list = new arraylist (); try {String fullPath = CombinePath (filepath, filename); 파일 = 새 파일 (fullPath); list.addall (filetools.sed (file, charset)); } catch (Exception Ex) {j2Log (null, null, ex); } 반환 목록; } / ** * sed 텍스트 파일 읽기 * * @param fullpath * @param charset * @return * / public static list <string> sed (String fullPath, String charset) {list <string> list = new arrayList (); try {file file = new File (fullPath); list.addall (filetools.sed (file, charset)); } catch (Exception Ex) {j2Log (null, null, ex); } 반환 목록; } / ** * sed 텍스트 파일 읽기 * * @param 파일 * @param charset * @return * / public static list <string> sed (파일 파일, 문자열 charset) {list <string> list = new arraylist (); BufferedReader BuffErreader = null; if (null == charset || "".Equals (charSet)) {charset = "utf-8"; } try {if (! file.exists () || file.isdirectory ()) {새 filenotfoundException (); } string fullPath = file.getPath (); bufferReader = new bufferedReader (new inputStreamReader (new FileInputStream (fullPath), charset); 문자열 온도; for (int i = 0; }} catch (예외 예) {j2log (null, null, ex); } 마침내 {if (null! = BuffErreader) {try {buffErreader.close (); } catch (ioexception ex) {j2log (null, null, ex); }}} 리턴 목록; } / ** * 고양이 읽기 텍스트 파일 * * @param filepath * @param filename * / public static byte [] cat (문자열 filepath, String filename) {byte [] output = {}; try {String fullPath = CombinePath (filepath, filename); 파일 = 새 파일 (fullPath); output = filetools.cat (파일); } catch (Exception Ex) {j2Log (null, null, ex); } 리턴 출력; } / ** * 고양이 읽기 텍스트 파일 * * @param fullpath * @return * / public static byte [] cat (String fullPath) {byte [] output = {}; try {file file = new File (fullPath); output = filetools.cat (파일); } catch (Exception Ex) {j2Log (null, null, ex); } 리턴 출력; } / ** * 고양이 읽기 텍스트 파일 * * @param 파일 * @return * / public static byte [] cat (파일 파일) {inputStream in = null; 바이트 [] 출력 = {}; try {if (! file.exists () || file.isdirectory ()) {새 filenotfoundException (); } string fullPath = file.getPath (); 긴 길이 = du (file, false); long _2m = 2097152; 바이트 [] 바이트 = 새로운 바이트 [(int) 길이]; in = new FileInputStream (fullPath); for (int count = 0; count! = -1;) {if (길이> 16 * _2m) {길이 = 4 * _2m; } else if (길이> 8 * _2m) {길이 = 2 * _2m; } else if (길이> 4 * _2m) {길이 = _2m; } else if (길이> 2 * _2m) {길이 = _2m / 2; } else if (길이> _2m) {길이 = _2m / 4; } else {길이 = 4096; } bytes = 새로운 바이트 [(int) 길이]; count = in.read (바이트); 출력 = concatArray (바이트, 출력); 길이 = in.available (); }} catch (예외 예) {j2log (null, null, ex); } 마침내 {if (null! = in) {try {in.close (); } catch (Exception Ex) {j2Log (null, null, ex); }}} return output; } / ** * Merge array * * @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); NewArray를 반환하십시오. } / ** * dd 파일 FullPath 컨텐츠 작성 * @param filepath * @param filename * @param isappend * / public static void dd (문자열 filepath, String filename, byte [] content, boolean isappend) {try {string fullpath = combinepath (filepath, filename); 파일 = 새 파일 (fullPath); filetools.dd (파일, 내용, Isappend); } catch (Exception Ex) {j2Log (null, null, ex); }} / ** * dd 파일 fullPath 컨텐츠 내용 * @param fullpath * @param content * @param isappend * / public static void dd (string fullpath, byte [] content, boolean iSappend) {file {file = new File (fullPath); filetools.dd (파일, 내용, Isappend); } catch (Exception Ex) {j2Log (null, null, ex); }} / ** * dd 파일 fullpath 컨텐츠 내용 * @param file * @param content * @param isappend * / public static void dd (파일 파일, byte [] content, boolean isappend) {fileoutputStream fileoutputStream = null; try {if (! file.exists ()) {file.createnewfile (); } fileoutputStream = 새 FileOutputStream (file, isappend); fileoutputStream.write (content); } catch (Exception Ex) {j2Log (null, null, ex); } 마침내 {try {if (null! = fileoutputStream) {fileoutputStream.close (); }} catch (ioexception ex) {j2log (null, null, ex); }}}}} / ** * FullPath * @param filepath * @param filename * @param void write (String FilePath, String Filename, String Content) {try {String fullPath = CombinePath (filepath, filename); 파일 = 새 파일 (fullPath); filetools.write (파일, 내용, true); } catch (Exception Ex) {j2Log (null, null, ex); }} / ** * FullPath * @param fullpath * / public static void write (String fullPath, String Content) {try {file file = new File (fullPath); filetools.write (파일, 내용, true); } catch (Exception Ex) {j2Log (null, null, ex); }} / ** * FullPath * @param content * / public static void write (파일 파일, 문자열 내용) {try {filetools.write (file, content, true); } catch (Exception Ex) {j2Log (null, null, ex); }} / ** * FullPath * @param filepath * @param filename * @param content * @param isappend * / public static void write (String filepath, String filename, String Content, Boolean Isappend) {try {string fullPath = combinePath (filepath, filename); 파일 = 새 파일 (fullPath); filetools.write (파일, 내용, Isappend); } catch (Exception Ex) {j2Log (null, null, ex); }} / ** * FullPath * @param fullpath * @param isappend * / public static void write (String fullPath, String Content, Boolean Isappend) {try {file file = new File (fullPath); filetools.write (파일, 내용, Isappend); } catch (Exception Ex) {j2Log (null, null, ex); }} / ** * FullPath * @param content * @param isappend * / public static void write (파일 파일, 문자열 콘텐츠, 부울 ISAppend) {filewriter filewriter = null; try {if (! file.exists ()) {file.createnewfile (); } filewriter = new FileWriter (file.getPath (), IsAppend); filewriter.write (컨텐츠); } catch (Exception Ex) {j2Log (null, null, ex); } 마침내 {if (null! = filewriter) {try {filewriter.close (); } catch (ioexception ex) {j2log (null, null, ex); }}}}} / ** * 테일 파일의 인덱스 위치에 파일 컨텐츠 추가 * * @param filepath * @param filename * @param index * / public static void tail (문자열 filepath, 문자열 파일 이름, 긴 색인) {try {string fullpath = combinepath (filepath, filename); 파일 = 새 파일 (fullPath); filetools. tail (파일, 컨텐츠, 색인); } catch (Exception Ex) {j2Log (null, null, ex); }} / ** * 테일 파일 컨텐츠 추가 파일의 인덱스 위치에 * @param fullpath * @param index * / public static void tail (문자열 fullPath, 문자열 내용, 긴 색인) {try {file file = new File (fullPath); filetools. tail (파일, 컨텐츠, 색인); } catch (Exception Ex) {j2Log (null, null, ex); }} / ** * 테일 파일 컨텐츠 추가 파일의 인덱스 위치에 * @param 파일 * @param 컨텐츠 * @param index * / public static void tail (파일 파일, 문자열 내용, 긴 색인) {randomAccessFile RandomAccessFile = null; try {if (! file.exists ()) {file.createnewfile (); } randomAccessFile = 새로운 randomAccessFile (file.getPath (), "rw"); randomaccessfile.seek (색인); randomaccessfile.writeBytes (컨텐츠); } catch (Exception Ex) {j2Log (null, null, ex); } lANDE {if (null! = randomAccessFile) {try {randomaccessfile.close (); } catch (Exception Ex) {j2Log (null, null, ex); }}}}} / ** * mkdir 디렉토리 작성 * * @param filepath * @param filename * @return * / public static file mkdir (String filepath, string filename) {file file = null; try {String fullPath = CombinePath (filepath, filename); 파일 = 새 파일 (fullPath); file = mkdir (파일); } catch (Exception Ex) {j2Log (null, null, ex); } 반환 파일; } / ** * mkdir 디렉토리 작성 * * @param fullpath * @return * / public static 파일 mkdir (String fullPath) {file file = null; try {file = new File (fullPath); file = mkdir (파일); } catch (Exception Ex) {j2Log (null, null, ex); } 반환 파일; }/** * mkdir 디렉토리 작성 * * @param file * @return */public static file mkdir (파일) {try (! file.exists ()) {file.mkdir (); // 폴더가 존재하지 않으면 생성}} catch (Exception ex) {j2log (null, null, ex); } 반환 파일; } / ** * 터치 터치 파일 생성 * * @param filepath * @param filename * / public static void touch (문자열 filepath, String filename) {try {String fullPath = combinePath (filepath, filename); 파일 = 새 파일 (fullPath); 터치 (파일); } catch (Exception Ex) {j2Log (null, null, ex); }} / ** * 터치 파일 작성 * * @param fullpath * / public static void touch (String fullPath) {try {file file = new File (fullPath); 터치 (파일); } catch (Exception Ex) {j2Log (null, null, ex); }}/** * 터치 파일 생성 * * @param 파일 */public static void touch (파일 파일) {try (! file.exists ()) {file.createnewfile (); // 파일이 존재하지 않는 경우 작성}} catch (예외 Ex) {j2log (null, null, ex); }} / ** * rm 파일 삭제 * * @param filepath * @param filename * / public static void rm (String Filepath, String Filename) {try {String fullPath = CombinePath (filepath, filename); 파일 = 새 파일 (fullPath); rm (파일); } catch (Exception Ex) {j2Log (null, null, ex); }} / ** * rm 파일 삭제 * * @param fullpath * / public static void rm (String fullPath) {try {file file = new File (fullPath); rm (파일); } catch (Exception Ex) {j2Log (null, null, ex); }} / ** * rm 파일 삭제 * * @param 파일 * / public static void rm (파일 파일) {try {if (! file.exists ()) {strach new filenotfoundException (); } if (file.isfile ()) {file.delete (); }} catch (예외 예) {j2log (null, null, ex); }} / ** * rmdir 디렉토리 삭제 * * @param filepath * @param filename * @param loop * / public static void rmdir (문자열 filepath, 문자열 파일 이름, 부울 루프) {try {string fullpath = combinepath (filepath, filename); 파일 dir = 새 파일 (fullPath); rmdir (dir, loop); } catch (Exception Ex) {j2Log (null, null, ex); }} / ** * rmdir delete decretory * * @param fullpath * @param loop * / public static void rmdir (String fullpath, boolean loop) {try {file dir = new File (fullPath); rmdir (dir, loop); } catch (Exception Ex) {j2Log (null, null, ex); }} / ** * rmdir delete decriptory * * @param dir * @param loop * / public static void rmdir (파일, boolean loop) {try {if (! dir.exists ()) {strach new filenotfoundException (); } if (dir.isdirectory ()) {file [] files = dir.listfiles (); int length = files.length; for (int i = 0; i <length && longe && i ++) {if (files [i] .isdirectory ()) {rmdir (files [i], loop); } else {rm (파일 [i]); }} if (루프 || 길이 == 0) {dir.delete (); }}} catch (예외 예) {j2log (null, null, ex); }} / ** * du 실제 파일 크기를 가져옵니다 * * @param filepath * @param filename * @param loop * @return * / public static long du (문자열 filepath, 문자열 파일 이름, 부울 루프) {long size = 0; try {String fullPath = CombinePath (filepath, filename); 파일 = 새 파일 (fullPath); 크기 = du (파일, 루프); } catch (Exception Ex) {j2Log (null, null, ex); } 반환 크기; } / ** * du 실제 파일 크기를 가져옵니다 * * @param filepath * @param filename * @return * / public static long du (문자열 filepath, String filename) {long size = 0; try {String fullPath = CombinePath (filepath, filename); 파일 = 새 파일 (fullPath); size = du (파일, false); } catch (Exception Ex) {j2Log (null, null, ex); } 반환 크기; } / ** * du 실제 파일 크기를 얻습니다 * * @param fullpath * @return * / public static long du (String fullPath) {long size = 0; try {file file = new File (fullPath); size = du (파일, false); } catch (Exception Ex) {j2Log (null, null, ex); } 반환 크기; } / ** * du 실제 파일 크기를 가져옵니다 * * @param 파일 * @return * / public static long du (파일 파일) {long size = 0; try {size = du (file, false); } catch (Exception Ex) {j2Log (null, null, ex); } 반환 크기; } / ** * du 실제 파일 크기를 가져옵니다 * * @param fullpath * @param loop * @return * / public static long du (String fullPath, 부울 루프) {long size = 0; try {file file = new File (fullPath); 크기 = du (파일, 루프); } catch (Exception Ex) {j2Log (null, null, ex); } 반환 크기; } / ** * du 실제 파일 크기를 가져옵니다 * * @param 파일 * @param loop * @return * / public static long du (파일 파일, 부울 루프) {filechannel filechannel = null; 긴 크기 = 0; try {if (! file.exists ()) {strach new filenotfoundexception (); } if (file.isfile ()) {fileInputStream fis = new FileInputStream (file); filechannel = fis.getChannel (); size = filechannel.size (); } else if (file.isdirectory ()) {file [] files = file.listfiles (); int length = files.length; for (int i = 0; i <longth && longe && loop; i ++) {if (files [i] .isdirectory ()) {du (files [i], loop); } else {size += du (파일 [i], false); }}}} catch (예외 예외) {j2log (null, null, ex); } 마침내 {if (null! = filechannel) {try {filechannel.close (); } catch (Exception Ex) {j2Log (null, null, ex); }}} 반환 크기; }}위의 내용은이 기사에 관한 모든 것입니다. 모든 사람의 학습에 도움이되기를 바랍니다.