1. copy the file content:
ImportJava. Io. file;
ImportJava. Io. filewriter;
ImportJava. Io. ioexception;
ImportJava. Io. inputstream;
ImportJava. Io. Writer;
ImportOrg. Apache. commons. Io. fileutils;
ImportOrg. Apache. commons. Io. ioutils;
Public
ClassFilecopyexample {
Public
Static
VoidMain (string [] ARGs ){
Try{File src =
NewFile ("test. dat"); file DEST =
NewFile ("test. dat. Bak"); fileutils.
Copyfile(SRC, DEST );}
Catch(Ioexception IOE) {system.
Out. Println ("problem copying file .");}
Try{File src =
NewFile ("test. dat"); file dir =
NewFile ("./Temp"); fileutils.
Copyfiletodirectory(SRC, DIR );}
Catch(Ioexception IOE) {system.
Out. Println ("problem copying file to Dir .");}
Try{String = "blah"; file DEST =
NewFile ("test. tmp"); fileutils.
Writestringtofile(DEST, String, "ISO-8859-1 ");}
Catch(Ioexception IOE) {system.
Out. Println ("error writing out a string .");}
Try{Writer =
NewFilewriter ("test. dat"); inputstream = filecopyexample.
Class. Getclass (). getresourceasstream ("/IO/Web. xml"); ioutils.
Copy(Inputstream, writer); writer. Close (); inputstream. Close ();}
Catch(Ioexception e) {system.
Out. Println ("error copying data ");}
Try{File src =
NewFile ("test.txt"); outputstream output =
NewFileoutputstream (SRC); inputstream = filecopyexample.
Class. Getclass (). getresourceasstream ("/IO/Web. xml"); ioutils.
Copy(Inputstream, output); // writer. Close (); inputstream. Close (); output. Close ();}
Catch(Ioexception e) {system.
Out. Println ("error copying data") ;}} 2. File Deletion: file =
NewFile ("IO/Project. properties"); string display = fileutils.
Bytecounttodisplaysize(File. Length (); system.
Out. Println ("project. XML is" + display); fileutils.
Forcedelete(File) 3. read each row in the text: Import Java. io. file; import Java. io. ioexception; import Java. util. list; import Org. apache. commons. io. filesystemutils; import Org. apache. commons. io. fileutils; public class test {/*** @ Param ARGs * @ throws ioexception */public static void main (string [] ARGs) throws ioexception {// todo auto-generated method stub file = new file (test. class. getclass (). getresource ("/IO/web. XML ")). getFile (); List lines = fileutils. readlines (file, "UTF-8"); For (INT I = 0; I <lines. size (); I ++) system. out. println (lines. get (I ));}
}