它显示 07-07 16:34:48.270: W/System.err(6050): copy 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();