Results 1 to 3 of 3
  1. #1
    achill is offline Member
    Join Date
    Jan 2011
    Location
    Bielefeld, Germany
    Posts
    10
    Rep Power
    0

    Default IOException while writing a file to sdcard

    Hi there,

    I want to create a file on the sdcard but the application throws a IOException on specific smartphone.

    Here is my code:

    PHP Code:
    public void onClickTakePicture(final View v) {
        String storageState = Environment.getExternalStorageState();
        Log.v(TAG, "StorageState = " + storageState);
        if (storageState.equals(Environment.MEDIA_MOUNTED)) {
            mImage = new Image(this, mDb, _id);
            String path = Environment
    			.getExternalStorageDirectory().toString() + "/" + mImage.fileName;
            _imageFile = new File(path);
            if (!_imageFile.exists()) {
                Log.v(TAG, "Create image file " + path);
                _imageFile.getParentFile().mkdirs();
                try {
                    _imageFile.createNewFile();
                } catch (IOException e) {
                    Log.e(TAG, "IOException: " + e.toString());
                }
            } else {
                Log.v(TAG, "image file already created.");
            }
            if (!_imageFile.canWrite()) {
                Log.e(TAG, "Can't write to File.");
            }
    
            cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri
                    .fromFile(_imageFile));
            try {
                startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST);
                Log.v(TAG, "Start Activity 'ImageCapture'");
            } catch (Exception e) {
                Log.e(TAG, "Exception while capturing image: " + e.toString());
            }
        } else {
            Log.v(TAG, "SDCard not mounted.");
            Toast.makeText(this, "SDCard not mounted.", Toast.LENGTH_LONG)
                    .show();
        }
    }
    This works fine on the emulator and several smartphones like HTC Desire or HTC Legend. But on Motorola Defy an IOException is thrown.

    There is enough space left on the sdcard and I can copy files onto the sdcard via the file browser of DDMS in Eclipse. The Permission to write onto external storage is set in the manifest.

    :confused:

  2. #2
    achill is offline Member
    Join Date
    Jan 2011
    Location
    Bielefeld, Germany
    Posts
    10
    Rep Power
    0

    Default

    Problem is solved! :D

    The SDCard was formatted with FAT16 :eek: thus the max count of entries in the root directory is 512!
    That was too low for my application.

  3. #3
    Kratos321's Avatar
    Kratos321 is offline Member
    Join Date
    May 2011
    Posts
    31
    Rep Power
    0

    Default

    The problem is that your SD card is formatted with FAT16 so you can only have 512 entries in the root directory. So it's probably too low for your application.

Similar Threads

  1. Replies: 1
    Last Post: 02-27-2010, 02:29 AM
  2. Replies: 5
    Last Post: 11-22-2009, 05:48 PM
  3. Replies: 9
    Last Post: 10-20-2009, 11:52 AM
  4. Replies: 3
    Last Post: 05-10-2009, 12:31 AM
  5. Replies: 9
    Last Post: 07-10-2008, 05:52 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •