java中使用IO流复制文件

时间:2024-01-05 15:15:44
public class TestIO {

	public static void main(String[] args) {
// TODO Auto-generated method stub
try {
String in="C:\\Users\\Pei\\Desktop\\b14b9472a2c83047e35c31c91fbb88e3.mp4";
String out="C:\\Users\\Pei\\Desktop\\电视.mp4";
BufferedInputStream bis=new BufferedInputStream(new FileInputStream(new File(in)));
BufferedOutputStream bos=new BufferedOutputStream(new FileOutputStream(new File(out)));
byte[]bt=new byte[1024];
int count;
while((count=bis.read(bt))!=-1){
bos.write(bt, 0, count);
}
bis.close();
bos.close();
} catch (Exception e) {
e.printStackTrace(); }
}
}