it display 07-07 16:34:48.270: W/System.err(6050): copy java.io.IOException
i already given the permission
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
File Copy code :
File file = new File("/mnt/sdcard/infobooks/");
if (file.exists() == false) {
file.mkdirs();
}
InputStream myInput = this.getAssets().open("Book4.pdf");
String outFileName = Environment.getExternalStorageDirectory()+"/infobooks/Book4.pdf";
File file2=new File(outFileName);
file2.createNewFile();
FileOutputStream myOutput = new FileOutputStream(outFileName);
// transfer bytes from the inputfile to the outputfile
byte[] buffer = new byte[1024];
int length;
while ((length = myInput.read(buffer)) > 0) {
myOutput.write(buffer, 0, length);
}
// Close the streams
myOutput.flush();
myOutput.close();
myInput.close();
From the sounds of it, your error isn’t related to writing to the external storage but rather reading from the assets. Does the file ‘Book4.pdf’ exist in the assets directory? How big is it? What version of Android are you running? There was a time when Android had a limit on file size in assets when compression was being used. Prior to Android 2.3, the AssetManager couldn’t read large compressed files (where large meant over 1MB in uncompressed state). The way around this was to not compress the file (by giving it an extension for which aapt skips compression, such as jpg or png), going to command-line builds, or splitting the files into smaller chunks then reconstituting them on the device.
Without a full stacktrace, however, we can’t really know what the cause of the error is.