将每天学的东西贴上来: 
1. Constructing a Filename Path 
Java代码  
  1. String path = File.separator + "a" + File.separator + "b";  
  2. System.out.println("-----------> "+path);  


2.Creating a File 
Java代码  
  1.  File file = new File("filename.txt");  
  2.  // Create file if it does not exist  
  3. boolean success = file.createNewFile();  


3.Getting the Size of a File 
Java代码  
  1. File file = new File("filename.txt");  
  2. // Get the number of bytes in the file  
  3. long length = file.length();  
  4. System.out.println("length------------->"+length);  


4.Renaming a File or Directory 
Java代码  
  1. // File (or directory) with old name  
  2.         File file = new File("filename.txt");  
  3.         // File (or directory) with new name  
  4.         File file2 = new File("file.txt");  
  5.         // Rename file (or directory)  
  6.         boolean success = file.renameTo(file2);  
  7.         if (!success) {  
  8.             // File was not successfully renamed  
  9.         }  
posted on 2011-04-15 13:50  kitea  阅读(87)  评论(0)    收藏  举报