Package com.wen;
Import java.io. *;
/ ** *
Title: Common Directory file operation class p> *
description: p> *
Copyright: Copyright (c) 2004 p> *
Company: < / p> * @Author experaner * @version 1.0 * /
Public class fileutils {public fileUtils () {}
public static void copy (File src, File dest, boolean cover) throws IOException {FileInputStream fis = new FileInputStream (src); FileOutputStream fos = new FileOutputStream (dest); byte buf [] = new byte [1024]; int i; try {While ((i = fis.read (buf))> = 0) {Fos.Write (buf, 0, i);}} finally {try {fis.close ();} catch (exception exception1) {}
Try {fos.close ();} catch (exception exception) {}}}
Public Static Void Copy (String Src, String Dest, Boolean Cover) THROWS IEXCEPTION {File Fsrc = New File (src); File FDest = New File (DEST); COPY (FSRC, FDEST, Cover);
Public Static Void CopyTree (File SRC, File Dest, Boolean Cover "" {Copy (src, dest, cover);} else {file children;} else {file children [] = src.listfiles (); for (INT i = 0; i Public Static Void CopyTree (String Src, String Dest, Boolean Cover) THROWS IEXCEPTION {file fsrc = new file (src); file fdest = new file (dest); CopyTree (FSRC, FDEST, Cover);} public static void movetree (File src, File dest, boolean cover) throws IOException {copytree (src, dest, cover); deltree (src);} public static void deltree (File f) {File children [] = f.listFiles ( ); If (children! = Null && children.Length! = 0) {for (int i = 0; i Public static void deltree (string path) {file f = new file (path); Deltree (f); Public Static Void Move (String src, String Dest, Boolean Cover) THROWS IEXCEPTION {File Fsrc = New File (src); File FDest = New File (DEST); COPY (FSRC, FDEST, Cover); fsrc.delete (); } Public Static Boolean Find (File Root, Filefilter Filter) {if (Filter.Accept (root)) {Return True;} File children [] = root.listfiles (); if (children == null || children.length == 0) {Return False;} For (int i = 0; I Return false;} Public Static Boolean Contains (File File, String Suffix) {if (! file.exists () ||! file.Indirectory ()) {Return False;} File Children [] = file.listfiles (); for (int i = 0; I Return false;} // Read the single line file content public static string getfline (string filepath) {string fc = null; Try {BufferedReader f = new bufferedreader (new fileReader (filepath)); fc = f.readline (); f.close ();} catch (ioException e) {system.out.println ("Readline Problem, Terminating.") } Return fc;} / / Read the contents of the single line file and add a write to the public static string getiline (string filepath) {string fc = null; Try {bufferedreader f = new bufferedreader (new fileReader (filepath)); fc = f.readline (); long l = long.parselong (fc); l ; fc = string.valueof (l); f.close (); BufferedWriter BW = New FileWriter (New FileWriter); BW.WRITE (FC "/ N"); bw.flush (); bw.close ();} catch (ooException e) {system.out.println "Readline Problem, Terminating."); Return fc; Public static string getfileext (string filename) {string ext = ""; int dot = filename.lastIndexof ("."); if (dot! = -1) {ext = filename.substring (Dot 1);} returnix EXT } Public static string getFullFileName (String filepath) {string filepath = filepath; int i = filepath.lastindexof ("/"); if (i! = -1) {filename = filepath.substring (i 1);} return filename; } Public static string getFileName (string filepath) {string filepath = filepath; int i = filepath.lastIndexof ("/"); int J = filepath.lastIndexof ("."); if (i! = -1) {filename = filepath . Substring (i 1, j);} returnifename;} Public static string getPath (string filepath) {string path = ""; int i = filepath.lastindexof ("/"); if (i! = -1) {path = filepath.substring (0, i);} returnoph PUBLIC STATIC Boolean Writeto (String Path, String Info) {Try {File F = New File (PATH); PrintWriter Out = New PrintWriter (New FileWriter (f)); Out.Print (Info); Out.close () Return True;} catch (ioexception e) {returnif value;}} // Additional string public static boolean append (string path, string info) {try {file f = new file (path); printwriter out; filewriter thefile; if (f.exists ()) {thefile = new filewriter (path, True); out = new printwriter (thefile);} else {thefile = new filewriter (f); out = new printwriter;} out.print (INFO "/ N"); out.close (); thefile .close (); Return true;} catch (ioException e) {return false;}} Public static string getfilecontent (file srcfile) {string strreturn = "" Try {BufferedInputStream Buff = New BufferedInputStream (New FileInputStream (srcfile)); INT IN = 0; Do {IN = buff.read (); if (in! = -1) {strreturn = (char) in;}} while (in! = -1); Return strreturn;} catCH (Exception E) {return strreturn;}} Public static string getfilecontent (string fpath) {file srcfile = new file (fpath); return getfilecontent (srcfile);}