本帖最后由 q19871127 于 2015-6-12 19:51 编辑
代码如下 我用字符流和字节流复制同一个avi文件大小为40mb,字节流 复制正常,字符流复制完只有35MB.
- import java.io.BufferedInputStream;
- import java.io.BufferedOutputStream;
- import java.io.BufferedReader;
- import java.io.BufferedWriter;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileOutputStream;
- import java.io.FileReader;
- import java.io.FileWriter;
- import java.io.IOException;
- public class Demo {
- public static void main(String[] args) throws IOException {
- File f1=new File("D:\\1.avi");
- File f2=new File("E:\\zifu.avi");
- File f3=new File("E:\\zijie.avi");
-
- BufferedInputStream bfin=new BufferedInputStream(new FileInputStream(f1));
- BufferedOutputStream bfout=new BufferedOutputStream(new FileOutputStream(f2));
- byte[] bytearr=new byte[1024];
- int x=0;
- while((x=bfin.read(bytearr))!=-1){
- bfout.write(bytearr,0,x);
- }
- bfin.close();
- bfout.close();
-
- BufferedReader bfr=new BufferedReader(new FileReader(f1));
- BufferedWriter bfw=new BufferedWriter(new FileWriter(f3));
- char[] chararr=new char[1024];
- int s=0;
- while((s=bfr.read(chararr))!=-1){
- bfw.write(chararr, 0, s);
- }
- bfr.close();
- bfw.close();
- }
- }
复制代码 |