它顯示07-07 16:34:48.270:W/System.err的(6050):複製產生java.io.IOException 我已經給出的許可機器人複製文件顯示錯誤
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
文件複製代碼:
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();
在這裏發佈您的整個日誌。 – 2012-07-07 11:16:18
嘗試字符串outFileName ='Environment.getExternalStorageDirectory()getAbsolutePath()+ 「/ infobooks/Book4.pdf」;'代替'字符串outFileName = Environment.getExternalStorageDirectory()+ 「/ infobooks/Book4.pdf」;' – 2012-07-07 11:16:25
我調試我的代碼錯誤是在while((length = myInput.read(buffer))> 0)this但是我不不是什麼它 – Youddh 2012-07-07 11:21:06