- import java.io.File;
- import java.io.IOException;
- public class Main {
- private static int num;
- private static File file;
- public static void main(String args[]) throws IOException
- {
- file = new File("C:\\a\\b\\c\\test.txt");
- String str[] = file.list();
- String path = file.getPath();
- File file2 =save(path);
- // file2.createNewFile();
-
-
-
- }
- public static File save(String path)
- {
- if(!file.exists())
- {
- if(num==0)
- {
- file.getParentFile().mkdirs();
- try {
- file.createNewFile();
- } catch (IOException e) {
- // TODO 自動產生的 catch 區塊
- e.printStackTrace();
- }
- }
- return save(file.getPath());
- }else
- {
- return file;
- }
- }
- }
複製代碼 |