java - android copy file display error -
it display 07-07 16:34:48.270: w/system.err(6050): copy java.io.ioexception given 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 inputfile outputfile byte[] buffer = new byte[1024]; int length; while ((length = myinput.read(buffer)) > 0) { myoutput.write(buffer, 0, length); } // close streams myoutput.flush(); myoutput.close(); myinput.close();
from sounds of it, error isn't related writing external storage rather reading assets. file 'book4.pdf' exist in assets directory? how big it? version of android running? there time when android had limit on file size in assets when compression being used. prior android 2.3, assetmanager couldn't read large compressed files (where large meant on 1mb in uncompressed state). way around not compress file (by giving extension aapt skips compression, such jpg or png), going command-line builds, or splitting files smaller chunks reconstituting them on device.
without full stacktrace, however, can't know cause of error is.
Comments
Post a Comment