0

The problem is that in the first start of my app i load some images from the drawable folder and then put them into my storage using this function:

1- I first make them as bitmap

Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.autobus);

and then I convert them using this function

private String saveToInternalSorage(Bitmap bitmapImage, String imagename) throws IOException{
    ContextWrapper cw = new ContextWrapper(getApplicationContext());
     // path to /data/data/yourapp/app_data/imageDir
    File directory = cw.getDir("imageDir", Context.MODE_PRIVATE);
    // Create imageDir
    File mypath=new File(directory,imagename);

    FileOutputStream fos = null;
    try {           
        fos = new FileOutputStream(mypath);
   // Use the compress method on the BitMap object to write image to the OutputStream
        bitmapImage.compress(Bitmap.CompressFormat.PNG, 100, fos);
    } catch (Exception e) {
          e.printStackTrace();
    } finally {
          fos.close(); 
    } 
    return directory.getAbsolutePath();
}

But now I need to do the same for a sound , I need to store the sound fields in the raw section in the internal memory in order to use them later .

So if some one can help me that would be gentle of him , PS: I store the path to those files in my SQLite data base.

svarog
  • 9,477
  • 4
  • 61
  • 77
Kingofkech
  • 129
  • 9

1 Answers1

1

If you use an InputStream to read, use an OutputStream to write, i.e. a BufferedOutputStream-wrapped FileOutputStream. Also, your code is pretty inefficient, as it only copies one byte at a time. I'd suggest creating a byte array buffer and using these relevant read/write methods:

int BufferedInputStream.read(byte[] buffer, int offset, int length)void BufferedOutputStream.write(byte[] buffer, int offset, int length)

For more detail use this link it is help you

Community
  • 1
  • 1
Akshay More
  • 359
  • 2
  • 13