Results 1 to 3 of 3
- 03-11-2011, 01:15 PM #1
Member
- Join Date
- Jan 2011
- Location
- Bielefeld, Germany
- Posts
- 10
- Rep Power
- 0
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:
This works fine on the emulator and several smartphones like HTC Desire or HTC Legend. But on Motorola Defy an IOException is thrown.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(); } }
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:
- 05-11-2011, 01:12 PM #2
Member
- Join Date
- Jan 2011
- Location
- Bielefeld, Germany
- Posts
- 10
- Rep Power
- 0
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.
- 05-11-2011, 10:08 PM #3
Similar Threads
-
Im writing to a file and i want to skip lines while writing to a text file.
By Broden_McDonald in forum New To JavaReplies: 1Last Post: 02-27-2010, 01:29 AM -
java.io.IOException: error=2, No such file or directory
By NARs in forum New To JavaReplies: 5Last Post: 11-22-2009, 04:48 PM -
Reading and Writing the contents of a file to another file
By priyankatxs in forum New To JavaReplies: 9Last Post: 10-20-2009, 10:52 AM -
[SOLVED] how to reading binary file and writing txt file
By tOpach in forum New To JavaReplies: 3Last Post: 05-09-2009, 11:31 PM -
swapping the contents of the file and writing to another file
By Ms.Ranjan in forum New To JavaReplies: 9Last Post: 07-10-2008, 04:52 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks