赞
踩
一般来说是因为父路径缺乏,或者文件没创建。
举一个例子
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();
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。