Java复制二进制文件
Posted 水色季夏
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Java复制二进制文件相关的知识,希望对你有一定的参考价值。
常用方法使用高效缓冲字节流
?
BufferedInputStream和BufferedOutputStream
?
import java.io.*;
public class BufferCopy {
public static void main(String[] args) {
//定义一个高效缓存字节流
BufferedInputStream in = null;
BufferedOutputStream out = null;
try {
//创建一个高效缓存字节流对象
in = new BufferedInputStream(new FileInputStream("C:/yonige.png"));
out = new BufferedOutputStream(new FileOutputStream("D:/ComingSpring.png"));
//定义一个字节数组
byte[] bs = new byte[1024];
//定义一个标志
int len = -1;
while((len = in.read(bs)) != -1){
out.write(bs, 0, len);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if(out != null){
out.close();
}
if(in != null){
in.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
以上是关于Java复制二进制文件的主要内容,如果未能解决你的问题,请参考以下文章
当我切换到包含片段的活动时应用程序崩溃(二进制 XML 文件第 10 行:二进制 XML 文件第 10 行:膨胀类片段时出错)