android FileNotFoundException(Is a Directory)解决办法
来源:互联网 发布:aws 阿里云 比较 编辑:程序博客网 时间:2024/06/02 05:44
最近公司项目要求把从服务器读取的图片存到本地SD卡中,一开始以为很轻松啊,听着小曲,看着视频,敲着代码,这小资生活。。。。咳咳,扯远了,OK,代码敲完了,如下:
public void GetIamge(String urlPath){ HttpClient client = new DefaultHttpClient(); HttpGet get = new HttpGet(urlPath); //String name = urlPath.substring(urlPath.lastIndexOf(".")); File dir = new File(Environment.getExternalStorageDirectory() + "/YunJian"); File file = new File(dir, "header.jpg"); if(!dir.exists()){ dir.mkdirs(); } HttpResponse response = null; try { response = client.execute(get); InputStream inputStream = response.getEntity().getContent(); Bitmap bitmap = BitmapFactory.decodeStream(inputStream); FileOutputStream outputStream = new FileOutputStream(file); if(bitmap != null){ bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outputStream); } } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
一运行,报错:java.io.FileNotFoundException:XXX open falied: EISDIR(Is a directory)。傻眼了,不科学啊,怎么会把文件编译成文件夹呢。好吧,第一时间,发挥天才般的大脑。。。。。算了,还是找度娘吧,看了网上的方法,总结了一下:
- 可能是权限的问题,也就是没有加访问SD卡的权限;
- 可能是路径问题,有可能路径不存在导致的。
按照这两种可能去找问题,发现不对路,没办法了,去官网,看一下File类,这才发现File类的构造函数中:File(File, String)构造函数创建的对象是文件夹,File(String, String)函数创建的对象才是文件,所以只需把上诉代码中的
File file = new File(dir, "header.jpg")改为:
File file = new File(dir.getPath(), "header.jpg")就可以了。
0 0
- android FileNotFoundException(Is a Directory)解决办法
- Android异常java.io.FileNotFoundException:(Is a directory)
- Android异常java.io.FileNotFoundException:(Is a directory)
- Android-开发异常《java.io.FileNotFoundException (Is a directory)》
- 【cas】keytool error: java.io.FileNotFoundException: xxx (Is a directory)
- Linux cannot remove is a directory 解决办法
- Linux cannot remove is a directory 解决办法
- hadoop 问题 copyFromLocal: java.io.FileNotFoundException: Parent path is not a directory: /user/admini
- android:open failed: EISDIR (Is a directory)
- android failed:EISDIR(Is a directory)错误
- hadoop 报错Error: java.io.FileNotFoundException: Path is not a file:/xx1/xx2的解决办法
- hadoop 报错Error: java.io.FileNotFoundException: Path is not a file:/xx1/xx2的解决办法
- hadoop 报错Error: java.io.FileNotFoundException: Path is not a file:/xx1/xx2的解决办法
- Svn中Path is not a working copy directory解决办法
- Svn中Path is not a working copy directory解决办法
- bash:...: is a directory
- proj.android' is not a valid directory. && mkgroup 错误
- make xxx Is a directory
- 第四章 类和对象的进一步讨论
- Android项目更换开发环境时出现的 java.lang.VerifyError 异常解决办法
- 在线调试 微信打开的HTML5页面
- fatal error C1189: #error : WINDOWS.H already included. MFC apps must not #include
- Spring MVC @ResponseBody 中文乱码 解决方案
- android FileNotFoundException(Is a Directory)解决办法
- jQuery插件AjaxFileUpload文件上传实现Javascript多文件上传功能
- Sabresd板子上WM8962的耳机和功放的关系
- GC调优在Spark应用中的实践
- eclipse 编辑窗口不见了(打开左边的java、xml文件,中间不会显示代码)
- R语言学习笔记
- Hadoop面试题集锦
- delphi RTTI 反射技术
- Web Uploader