open Faild EISDIR (это каталог) .. как это исправить?

Каждый раз, когда он дает мне «невозможно декодировать поток java.io.FileNotFoundException: /: open Faild EISDIR (является каталогом)

как я могу избавиться от этой ошибки .. этот класс отлично работал во многих задачах, которые я выполнял !!

вот класс, который я использую для получения растровых изображений

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;
    }

person mnagy    schedule 24.02.2013    source источник
comment
Попробуйте использовать версию с двумя параметрами для создания файла: File tmpFile = new File(cacheDirectory, wpta_+position+.png); Это создаст файл внутри каталога в первом параметре. Кроме того, проверьте свою файловую систему и убедитесь, что вы случайно не создали там какие-то каталоги.   -  person Gabe Sechan    schedule 24.02.2013
comment
Я пытался, но это дало мне ту же ошибку   -  person mnagy    schedule 24.02.2013


Ответы (1)


Вам правильно нужно позвонить:

tmpFile.getParentFile().mkdirs();

перед созданием FileOutputStream.

Подробнее: FileOutputStream аварийно завершает работу с ошибкой открытия: EISDIR (Это каталог) ошибка при загрузке изображения

person Morten Holmgaard    schedule 18.02.2014