[JAVA]字节流拷贝文件

import java.io.*;

public class CopyFile {

    public static void main(String[] args) {
//1、创建源
File in = new File("d:/test/1111.mp4");
File out = new File("d:/test/222.mp4");
//2、选择流
InputStream is = null;
OutputStream os = null; try {
//3、操作数据
is = new FileInputStream(in);
os = new FileOutputStream(out);
byte[] buf = new byte[1024*1024];
int length = -1;//记录实际读取到的长度
while ((length = is.read(buf)) != -1) {
os.write(buf, 0, length);
}
os.flush();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {//4、关闭流(先打开的后关闭)
try {
if (os != null)
os.close();
} catch (IOException e) {
e.printStackTrace();
}
try {
if (is != null)
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
上一篇:x264中I,P,B帧和PTS,DTS的关系


下一篇:描述实习/项目经历时可以采用STAR法则,来描述实习经历,突出优势。