Android 文件复制操作及优化(cpu的占用,资源的释放)
来源:互联网 发布:答案软件 编辑:程序博客网 时间:2024/05/22 06:18
//文件复制操作
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) {
i ++;
outBuff.write(b, 0, len);
if(i == 64){ // 每写512K 时间片停下 留资源给其他IO操作
try {
Thread.sleep(20);
} catch (InterruptedException e) {
e.printStackTrace();
}
i = 0;
}
}
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) {
i ++;
outBuff.write(b, 0, len);
if(i == 64){ // 每写512K 时间片停下 留资源给其他IO操作
try {
Thread.sleep(20);
} catch (InterruptedException e) {
e.printStackTrace();
}
i = 0;
}
}
// 刷新此缓冲的输出流
outBuff.flush();
//关闭流inBuff.close();
outBuff.close();output.close();
input.close();
b = null;
}
一,当文件很大时会占用IO通道所以因当将时间休息会让其他人上。
二,关闭打开的流,同时将临时申请的中间变量都赋值为null,便于回收,这样做是很有意义的。
- Android 文件复制操作及优化(cpu的占用,资源的释放)
- Android资源图片内存占用及优化
- Android资源图片内存占用及优化
- Android资源图片内存占用及优化
- Android资源图片内存占用及优化
- Android资源图片内存占用及优化
- Android资源图片内存占用及优化
- Android资源图片内存占用及优化
- Android资源图片内存占用及优化
- 在IIS6下w3wp.exe的内存及CPU占用不能及时释放问题
- Linux解决长时间占用CPU资源的方法(底半部)
- 对CPU资源占用100%的解决方法
- Mysql 占用cpu资源高的分析
- mysql占用CPU资源高的分析
- php-cgi进程占用cpu资源过大原因分析及解决(找出有问题的linux进程)
- php-cgi进程占用cpu资源过多负载高的原因分析及解决步骤
- php-cgi进程占用cpu资源过多负载高的原因分析及解决步骤
- php-cgi进程占用cpu资源过多负载高的原因分析及解决步骤
- uva 10004 - Bicoloring
- CreateAnonymousThread
- CGFloat CGPoint CGSize CGRect 绘图有关的类型
- GNU info 简介
- 分享自己整理的图像处理、模式识别资料
- Android 文件复制操作及优化(cpu的占用,资源的释放)
- 薛引娟:市场越冷越要投资
- uva 11234 - Expressions
- Flex4.5RadioButton皮肤的创建
- 《暗时间》读书笔记
- 《圣经》中的历史,与历史中的基督教[zhuan]
- IOS推送消息(java实现)
- chart图像刷新
- 理解奈奎斯特定理和香农定理