当前位置: 代码迷 >> J2SE >> 通过File类创建文件失败,该如何处理
  详细解决方案

通过File类创建文件失败,该如何处理

热度:65   发布时间:2016-04-24 12:18:44.0
通过File类创建文件失败
Java code
public static void main(String[] args) throws IOException {        File dir = new File("c/exam/haha");        if (dir.exists() && dir.isDirectory()) {            System.out.println("The directory already exits!".toUpperCase());        } else {            if (dir.mkdirs()) {                System.out.println("the directory has been created!".toUpperCase());                File f = new File(dir, "test.txt");                f.createNewFile();                f.setReadOnly();                System.out.println("end of creation".toUpperCase());            } else {                System.out.println("failed!".toUpperCase());            }        }    }


第一次运行时,输出创建成功的信息
而且再次运行也会提示目录已经存在
但是通过实际查看一下,发现并没有生成目录和文件,为什么?

------解决方案--------------------
创建了,在你项目根目录下生成了c\exam\haha\test.txt
------解决方案--------------------
刷新下工程目录。
  相关解决方案