【问题标题】:open Faild EISDIR (Is a Directory) .. how to fix this?打开失败的EISDIR(是目录)..如何解决这个问题?
【发布时间】:2013-02-24 08:53:38
【问题描述】:

每次它给我“无法解码流 java.io.FileNotFoundException: /: open Faild EISDIR (Is a Directory)”

我怎样才能摆脱这个错误..这个类在我完成的许多任务中都运行良好!!

这是我用来获取位图的类

private class ImageLoaderTask extends AsyncTask<HashMap<String, Object>, Void, HashMap<String, Object>>{

    @Override
    protected HashMap<String, Object> doInBackground(HashMap<String, Object>... hm) {

        InputStream iStream=null;
        String imgUrl = (String) hm[0].get("image");
        int position = (Integer) hm[0].get("position");

        URL url;
        try {
            url = new URL(imgUrl);

            // Creating an http connection to communicate with url
            HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();

            // Connecting to url
            urlConnection.connect();

            // Reading data from url
            iStream = urlConnection.getInputStream();

            // Getting Caching directory
            File cacheDirectory = getBaseContext().getCacheDir();

            // Temporary file to store the downloaded image
            File tmpFile = new File(cacheDirectory.getPath() + "/wpta_"+position+".png");

            // The FileOutputStream to the temporary file
            FileOutputStream fOutStream = new FileOutputStream(tmpFile);

            // Creating a bitmap from the downloaded inputstream
            Bitmap b = BitmapFactory.decodeStream(iStream);

            // Writing the bitmap to the temporary file as png file
            b.compress(Bitmap.CompressFormat.PNG,100, fOutStream);

            // Flush the FileOutputStream
            fOutStream.flush();

           //Close the FileOutputStream
           fOutStream.close();

            // Create a hashmap object to store image path and its position in the listview
            HashMap<String, Object> hmBitmap = new HashMap<String, Object>();

            // Storing the path to the temporary image file
            hmBitmap.put("photo",tmpFile.getPath());
            Log.d("photopah", tmpFile.getPath());

            // Storing the position of the image in the listview
            hmBitmap.put("position",position);

            // Returning the HashMap object containing the image path and position
            return hmBitmap;

        }catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

【问题讨论】:

  • 尝试使用两个参数版本的创建文件- File tmpFile = new File(cacheDirectory, "wpta_"+position+".png");这将在第一个参数的目录中创建一个文件。此外,请检查您的文件系统并确保您没有以某种方式意外地在那里创建一些目录。
  • 我试过但它给了我同样的错误

标签: android bitmapfactory


【解决方案1】:

您确实需要调用:

tmpFile.getParentFile().mkdirs();

在创建 FileOutputStream 之前。

查看更多:FileOutputStream crashes with "open failed: EISDIR (Is a directory)" error when downloading image

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-15
    • 2012-09-02
    • 1970-01-01
    相关资源
    最近更新 更多