返回列表 發帖
  1. import java.io.File;
  2. import java.io.IOException;


  3. public class Main {
  4.         private static int num;
  5.         private static File file;
  6.         public static void main(String args[]) throws IOException
  7.         {
  8.                 file = new File("C:\\a\\b\\c\\test.txt");
  9.                 String str[] = file.list();
  10.                 String path = file.getPath();

  11.                 File file2 =save(path);
  12. //                file2.createNewFile();
  13.                
  14.                
  15.                
  16.         }
  17.         public static File save(String path)
  18.         {
  19.                 if(!file.exists())
  20.                 {
  21.                          if(num==0)
  22.              {
  23.                      file.getParentFile().mkdirs();
  24.                      try {
  25.                                  file.createNewFile();
  26.                          } catch (IOException e) {
  27.                                  // TODO 自動產生的 catch 區塊
  28.                                  e.printStackTrace();
  29.                          }
  30.              }        
  31.                         return save(file.getPath());
  32.                 }else
  33.                 {
  34.                         return file;
  35.                 }
  36.         }
  37. }
複製代碼

TOP

返回列表