//文件复制操作
public static void copyFile(File sourceFile,File targetFile)throws IOException{
// 新建文件输入流并对它进行缓冲
FileInputStream input = new FileInputStream(sourceFile);
BufferedInputStream inBuff = new BufferedInputStream(input);
// 新建文件输出流并对它进行缓冲
FileOutputStream output = new FileOutputStream(targetFile);
BufferedOutputStream outBuff = new BufferedOutputStream(output);
// 缓冲数组
byte[] b = new byte[1024 * 8];
int len;
int i = 0; //
while ((len =inBuff.read(b)) != -1) {
public static void copyFile(File sourceFile,File targetFile)throws IOException{
// 新建文件输入流并对它进行缓冲
FileInputStream input = new FileInputStream(sourceFile);
BufferedInputStream inBuff = new BufferedInputStream(input);
// 新建文件输出流并对它进行缓冲
FileOutputStream output = new FileOutputStream(targetFile);
BufferedOutputStream outBuff = new BufferedOutputStream(output);
// 缓冲数组
byte[] b = new byte[1024 * 8];
int len;
int i = 0; //
while ((len =inBuff.read(b)) != -1) {

本文介绍了在Android中进行大文件复制时如何优化CPU占用和资源释放。通过合理使用IO通道,适时让CPU休息,并确保及时关闭输入输出流及释放中间变量,以提升效率并避免内存泄漏。
最低0.47元/天 解锁文章
2719

被折叠的 条评论
为什么被折叠?



