- package bbs.istak.org.tw;
- import java.io.File;
- import java.io.IOException;
- public class haung20180609 {
- static int n=0;
- public static void main(String[] args) {
- // TODO 自動產生的方法 Stub
- File newfile = filefunction("C:\\a\\b\\c\\test.txt");
- System.out.println(newfile.getPath());
- }
- public static File filefunction(String path)
- {
- File file = new File(path);
- if(!file.exists())
- {
- if(n==0)
- {
- file.getParentFile().mkdirs();
- try {
- file.createNewFile();
- } catch (IOException e) {
- // TODO 自動產生的 catch 區塊
- e.printStackTrace();
- }
- }
- file.mkdirs(); //往回建立
- n++;
- return filefunction(file.getPath());
- }
- else
- return file;
- }
- }
複製代碼 |