美文网首页
利用字节流复制文件

利用字节流复制文件

作者: Joy_yang17 | 来源:发表于2018-05-23 18:58 被阅读16次
    public class CopyFileByStream {
        public static void main(String[] args) {
         try {
            FileInputStream fileInputStream = new FileInputStream("learn.txt");
            FileOutputStream fileOutputStream = new FileOutputStream("learn22.txt",true);
            
            byte b [] = new byte[1024];
            int count = 0;
            long before = System.currentTimeMillis();
            while(fileInputStream.read(b)!= -1){
                   fileOutputStream.write(b);
                   count++;
            }
            //输入当前计算次数
            System.out.println(count);
            System.out.println(System.currentTimeMillis()-before);
            fileInputStream.close();
            fileOutputStream.close();
         
         } catch (Exception e) {
            e.printStackTrace();
        }
        }
    }
    

    相关文章

      网友评论

          本文标题:利用字节流复制文件

          本文链接:https://www.haomeiwen.com/subject/dqldjftx.html