Android:无法解码流/文件未找到错误

时间:2016-03-15 07:19:04

标签: java file bitmap filenotfoundexception

所以我将文件保存到文件夹时遇到问题。我一直在

  

“E / BitmapFactory:无法解码流:   java.io.FileNotFoundException:   /文件:/存储/模拟/ 0 /图片/像素/ JPG_2016-03-15   02:57:56.264-0400-1837017846.jpg:开放失败:ENOENT(没有这样的文件或   目录)“错误。

我已添加WRITE_EXTERNAL_STORAGE permission,所以我知道不是那样。

无论如何这里是我的文件代码和图片回调

public Bitmap createFile() throws IOException {
        String mCurrentPhotoPath;
        File image;
        File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory(
                Environment.DIRECTORY_PICTURES), "Pix");
        if (!mediaStorageDir.exists()) {
            if (!mediaStorageDir.mkdirs()) {
                Log.e("Pix", "failed to create directory");
                return null;
            }
        }
        String timeStamp = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSSZ").format(new Date());
        String imageFileName = "JPG_" + timeStamp;
        image = File.createTempFile(imageFileName, ".jpg", mediaStorageDir);
        mCurrentPhotoPath = "File:" + image.getAbsoluteFile();
        BitmapFactory.Options bmOptions = new BitmapFactory.Options();
        Bitmap bitmap = BitmapFactory.decodeFile(mCurrentPhotoPath, bmOptions);
        Log.d(TAG, "bitmap decoded :(" + bitmap);

        return bitmap;
    }

public Camera.PictureCallback mPicture = new Camera.PictureCallback() {
        @Override
        public void onPictureTaken(byte[] data, Camera camera) {
            Bitmap pictureFile = null;
            try {
                pictureFile = createFile();
            } catch (IOException e) {
                e.printStackTrace();
            }

            try {
                FileOutputStream fos = new FileOutputStream(String.valueOf(pictureFile));
                fos.write(data);
                fos.close();
            } catch (FileNotFoundException e) {
                Log.d(TAG, "File not found" + e.getMessage());
            } catch (IOException e) {
                Log.d(TAG, "Error accessing file" + e.getMessage());
            }

            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            mCamera.startPreview();
        }
    };

任何寻求答案的帮助或方向都非常适合!谢谢!

0 个答案:

没有答案