相关疑难解决方法(0)

如何与缺少的父目录一起创建新文件?

使用时

file.createNewFile();
Run Code Online (Sandbox Code Playgroud)

我得到以下异常

java.io.IOException: Parent directory of file does not exist: /.../pkg/databases/mydb
Run Code Online (Sandbox Code Playgroud)

我想知道是否有createNewFile创建缺少的父目录?

java

86
推荐指数
3
解决办法
4万
查看次数

如何在java(不是文件夹)中创建文件?

也许有点尴尬,但几个小时后我仍然无法用Java创建文件...

File file = new File(dirName + "/" + fileName);
try
{
    // --> ** this statement gives an exception 'the system cannot find the path'
    file.createNewFile();
    // --> ** this creates a folder also named a directory with the name fileName
    file.mkdirs();
    System.out.println("file != null");
    return file;
}
catch (Exception e)
{
    System.out.println(e.getMessage());
    return null;
}
Run Code Online (Sandbox Code Playgroud)

我在这里错过了什么?

java

15
推荐指数
1
解决办法
9181
查看次数

标签 统计

java ×2