FileNotFoundException(系统找不到指定的路径) [英] FileNotFoundException (The system cannot find the path specified)

查看:183
本文介绍了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'目录。应用程序对目录拥有完全的权限。



有什么想法?

解决方案


问题是因为我正在创建一个子目录来写文件。所以我现在有 C:\example\ ,并且想把我的文件写入 C:\ example \< date> \ < time> \< files>


您需要调用 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?

解决方案

The problem is because I'm creating a subdirectory in which to write the files. So I currently have C:\example\ and want to write my files in C:\example\<date>\<time>\<files>

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

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

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆