本文介绍了FileNotFoundException(系统找不到指定的路径)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  java.io.FileNotFoundException:C:\ ... \filename.xml (系统找不到指定的路径)

使用此代码:

  FileWriter fileWriter = new FileWriter(new File(path + date + timefilename.xml)); 
BufferedWriter writer = new BufferedWriter(fileWriter);
writer.write(data);

路径存在,但需要创建'date'和'time'目录。应用程序对目录拥有完全的权限。



有什么想法?

解决方案

您需要调用 File#mkdirs()
$ b

  File file = new File(C:/ example / newdir / NEWDIR / FILENAME.EXT); 
file.mkdirs();
// ...


I get this exception:

java.io.FileNotFoundException: C:\...\filename.xml (The system cannot find the path specified)

using this code:

FileWriter fileWriter = new FileWriter(new File(path + date + time "filename.xml"));
BufferedWriter writer = new BufferedWriter(fileWriter);
writer.write("data");

Path exists but directories for 'date' and 'time' need to be created. Application has full permissions on the directory.

Any ideas?

You need to call File#mkdirs() before writing.

File file = new File("C:/example/newdir/newdir/filename.ext");
file.mkdirs();
// ...

这篇关于FileNotFoundException(系统找不到指定的路径)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-18 05:30
查看更多