java 在項目中創建臨時文件夾,並稍後清除

 String path = Thread.currentThread().getContextClassLoader().getResource("").getPath()+"/temp";
        File file = new File(path);
        if (!file.exists()){
            file.mkdir();
        }
        File file1 = new File(path + "/" + "test"+".jpg");
        if (!file1.exists()){
            try {
                boolean newFile = file1.createNewFile();
            } catch (IOException e) {
                e.printStackTrace();
            }

        }

        // 可採用異步刪除
        file1.delete();
        System.out.println(path);

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章