• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Directory and File Creation problems...

ninjasenses

Newbie
Feb 9, 2010
38
0
Hey I am currently trying to create a path and file for an image i am storing from the camera. There seems to a be a problem with path I am trying to create though. In the following method, Im getting an IO.FileNotFound error on this line: fileOutputStream = new FileOutputStream(
sdImageMainDirectory.toString() +"/" + expName + ".jpg");

java.io.FileNotFoundException: /mysdcard/myImages/ImageName.jpg

Code:
public static boolean StoreByteImage(Context mContext, byte[] imageData,
			int quality, String expName) {
        File sdImageMainDirectory = new File("/mysdcard/myImages");
        sdImageMainDirectory.mkdirs();
		FileOutputStream fileOutputStream = null;
		try {

			BitmapFactory.Options options=new BitmapFactory.Options();
			options.inSampleSize = 5;
			
			Bitmap myImage = BitmapFactory.decodeByteArray(imageData, 0,
					imageData.length,options);

			fileOutputStream = new FileOutputStream(
					sdImageMainDirectory.toString() +"/" + expName + ".jpg");

			BufferedOutputStream bos = new BufferedOutputStream(
					fileOutputStream);

			myImage.compress(CompressFormat.JPEG, quality, bos);

			bos.flush();
			bos.close();

		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return true;
	}
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones