使用时
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创建文件...
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 ×2