满意答案
public boolean copy() {
InputStream in = null;
OutputStream out = null;
byte[] buffer = new byte[1024*8];
try {
in = new BufferedInputStream(new FileInputStream(new File("file1的路径")),1024*8);
out = new BufferedOutputStream(new FileOutputStream(new File("file2的路径")),1024*8);
while (in.read(buffer) > 0) {
out.write(buffer);
}
out.flush();
} catch (FileNotFoundException e) {
e.printStackTrace();
return false;
} catch (IOException e) {
e.printStackTrace();
return false;
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (out != null) {
try {
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return true;
}
冲忙写了这个方法,应该可以用。
00分享举报