Directory and File Creation problems...


Last Updated:

  1. ninjasenses

    ninjasenses Active Member This Topic's Starter

    Joined:
    Feb 9, 2010
    Messages:
    38
    Likes Received:
    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 (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...