1. determine if the path is a file or a directory
File subdir=new file ("C:\\mp3"); if (Subdir.isdirectory ()) { // is the directory }file mp3=new File ("c:\\mp3\\ Avemaria.mp3 "); if (Mp3.isfile ()) { // is file }
2. list the files and subdirectories under the directory
New= dir.list (); for (int i=0; i<children.length; i++) { = Children[i]; ...}
3. File copy
Public Static voidCopyFile (file sourcefile, file targetfile)throwsIOException {bufferedinputstream Inbuff=NULL; Bufferedoutputstream Outbuff=NULL; Try { //Create a new file input stream and buffer itInbuff =NewBufferedinputstream (NewFileInputStream (sourcefile)); //Create a new file output stream and buffer itOutbuff =NewBufferedoutputstream (NewFileOutputStream (targetfile)); //Buffer Array byte[] B =New byte[1024 * 5]; intLen; while(len = Inbuff.read (b))! =-1) {Outbuff.write (b,0, Len); } //flush this buffered output streamOutbuff.flush (); } finally { //Close the stream if(Inbuff! =NULL) Inbuff.close (); if(Outbuff! =NULL) Outbuff.close (); } }
4. get the Temp directory for the operating system
String folder=system.getproperty ("Java.io.tmpdir");
Java New Travels 33----catalog file Operations