返回列表 發帖
  1. package mis.kuas.edu.tw;

  2. import java.io.File;

  3. public class FILE {

  4.         public static void main(String[] args) {
  5.                 // TODO 自動產生的方法 Stub
  6.         File file = new File("D://");
  7.         String dir[] = file.list();
  8.         for(int i=1; i<=dir.length; i++)
  9.         {
  10.                 System.out.println(dir[i]);
  11.         }       
  12.         }

  13. }
複製代碼

TOP

  1. package mis.kuas.edu.tw;

  2. import java.io.File;
  3. import java.io.IOException;

  4. public class FILE {

  5.         public static void main(String[] args) {

  6.                 File file = new File("C://a//b//c//TEST.txt");
  7.                
  8.                 if(!file.exists()){
  9.                         
  10.                         String path = file.getParentFile().getPath();
  11.                         File newfile = new File(path+"//TEST.txt");
  12.                         newfile.getParentFile().mkdirs();
  13.                         try {
  14.                                 newfile.createNewFile();
  15.                         } catch (IOException e) {
  16.                                 // TODO 自動產生的 catch 區塊
  17.                                 e.printStackTrace();
  18.                         }
  19.                         
  20.                 }
  21.                
  22.         }
  23. }
複製代碼

TOP

返回列表