如果想要把某一個檔案,複製到另一個地方,程式如下:
FileInputStream fis = null;
FileOutputStream fos = null;
try {
fis = new FileInputStream("/mnt/sdcard/sample.apk");
fos = new FileOutputStream("/mnt/sdcard/sample.apk");
byte[] buf = new byte[1024];
int i = 0;
while ((i = fis.read(buf)) != -1) {
fos.write(buf, 0, i);
}
if (fis != null) fis.close();
if (fos != null) fos.close();
}
catch (Exception e) {
e.printStackTrace();
}
FileInputStream fis = null;
FileOutputStream fos = null;
try {
fis = new FileInputStream("/mnt/sdcard/sample.apk");
fos = new FileOutputStream("/mnt/sdcard/sample.apk");
byte[] buf = new byte[1024];
int i = 0;
while ((i = fis.read(buf)) != -1) {
fos.write(buf, 0, i);
}
if (fis != null) fis.close();
if (fos != null) fos.close();
}
catch (Exception e) {
e.printStackTrace();
}
沒有留言:
張貼留言