沒有目錄建目錄,沒有檔案建檔案

瓜瓜東西發表於2014-05-28
package com.wanju.project001.zonghe.test;


import java.io.File;
import java.io.IOException;


public class TestFile {


    public static void main(String[] args) {
        File file = new File("D:/test/a");
        if (!file.exists()) {
            file.mkdirs();
            System.out.println("構建目錄");
        }
        file = new File(file, "a.jsp");
        if (!file.exists()) {
            try {
                file.createNewFile();
            } catch (IOException e) {
                e.printStackTrace();
            }
            System.out.println("構建檔案");
        } else {
            System.out.println("已經有了此檔案");
        }
    }
}

相關文章