返回列表 發帖
  1. package bbs.istak.org.tw;

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

  4. public class haung20180609 {

  5.         static int n=0;
  6.         public static void main(String[] args) {
  7.                 // TODO 自動產生的方法 Stub
  8.         File newfile = filefunction("C:\\a\\b\\c\\test.txt");
  9.         System.out.println(newfile.getPath());
  10.         }
  11.     public static File filefunction(String path)
  12.     {
  13.             File file = new File(path);
  14.             if(!file.exists())
  15.             {
  16.                     if(n==0)
  17.                     {
  18.                             file.getParentFile().mkdirs();
  19.                             try {
  20.                                         file.createNewFile();
  21.                                 } catch (IOException e) {
  22.                                         // TODO 自動產生的 catch 區塊
  23.                                         e.printStackTrace();
  24.                                 }
  25.                     }       
  26.                     file.mkdirs();  //往回建立
  27.                     n++;
  28.                     return filefunction(file.getPath());
  29.             }
  30.             else
  31.                     return file;
  32.     }
  33. }
複製代碼

TOP

返回列表