Cannot make file java.io.IOException: No such file or directory

前端 未结 8 1795
-上瘾入骨i
-上瘾入骨i 2020-12-06 09:11

I am trying to create a file on the filesystem, but I keep getting this exception:

java.io.IOException: No such file or directory

I have an

8条回答
  •  [愿得一人]
    2020-12-06 09:36

    If the directory ../.foo/bar/ doesn't exist, you can't create a file there, so make sure you create the directory first.

    Try something like this:

    File f = new File("somedirname1/somedirname2/somefilename");
    if (!f.getParentFile().exists())
        f.getParentFile().mkdirs();
    if (!f.exists())
        f.createNewFile();
    

提交回复
热议问题