1. Check out our companion app, Forums for Android! Download from Google Play

Directory and File Creation problems...

Discussion in 'Application Development' started by ninjasenses, Jul 5, 2010.

  1. ninjasenses

    ninjasenses Active Member
    Thread Starter
    15

    Feb 9, 2010
    38
    0
    15
    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 (Text):
    1. public static boolean StoreByteImage(Context mContext, byte[] imageData,
    2.             int quality, String expName) {
    3.         File sdImageMainDirectory = new File("/mysdcard/myImages");
    4.         sdImageMainDirectory.mkdirs();
    5.         FileOutputStream fileOutputStream = null;
    6.         try {
    7.  
    8.             BitmapFactory.Options options=new BitmapFactory.Options();
    9.             options.inSampleSize = 5;
    10.            
    11.             Bitmap myImage = BitmapFactory.decodeByteArray(imageData, 0,
    12.                     imageData.length,options);
    13.  
    14.             fileOutputStream = new FileOutputStream(
    15.                     sdImageMainDirectory.toString() +"/" + expName + ".jpg");
    16.  
    17.             BufferedOutputStream bos = new BufferedOutputStream(
    18.                     fileOutputStream);
    19.  
    20.             myImage.compress(CompressFormat.JPEG, quality, bos);
    21.  
    22.             bos.flush();
    23.             bos.close();
    24.  
    25.         } catch (FileNotFoundException e) {
    26.             // TODO Auto-generated catch block
    27.             e.printStackTrace();
    28.         } catch (IOException e) {
    29.             // TODO Auto-generated catch block
    30.             e.printStackTrace();
    31.         }
    32.  
    33.         return true;
    34.     }
     

    Advertisement

Share This Page

Loading...