首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

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

2012-01-10 
通过File类创建文件失败Java codepublic static void main(String[] args) throws IOException {File dir

通过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
[解决办法]
刷新下工程目录。

热点排行