当前位置:   article > 正文

java.io.filenotfoundexception:_Java IO FileNotFoundException:常用解决办法

java.io.filenotfoundexception

一般来说是因为父路径缺乏,或者文件没创建。

举一个例子

Android中

1,父路径缺乏

String path=Environment.getExternalStorageDirectory().getPath()+"/XianDian/";

XianDian目录是不存在的,所以加个判断

File parent =new File(path);

if(!parent.exists()){

parent.mkdirs();

}

2文件没创建

//filepath是要下载文件的路径,根据路径获得文件名

String name =filepath.split("/")[path.split("/").length-1];

//path是上面的path

String localPath =path+name;          File file =new File(localPath);

try {

//假如文件不存在,需创建

if(!file.exists()){

file.createNewFile();

}

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/892037?site
推荐阅读
相关标签
  

闽ICP备14008679号