zoukankan      html  css  js  c++  java
  • Java中在磁盘上复制文件

    • 使用字节流实现
              public static void main(String[] args) throws IOException {
      		InputStream in = new FileInputStream(new File("F:\test.py"));
      		byte[] bts = new byte[1024];
      		OutputStream out = new FileOutputStream(new File("D:\test\test.py"));
      		int len = 0;
      		while((len = in.read(bts))!=-1) {
      			out.write(bts, 0, len);
      		}
      		
      		out.close();
      		in.close();
      	}
      

        

    • 使用字符流实现
      • char数组作为缓存
                public static void main(String[] args) throws IOException {
        		FileReader r = new FileReader("F:\test.py");
        		FileWriter w = new FileWriter("D:\test\test2.py");
        		char[] buf = new char[1024];
        		int c ;
        		while((c=r.read(buf))!=-1) {
        			w.write(buf,0,c);
        		}
        		r.close();
        		w.close();
        	}
        

          

      • 不使用数组做缓存,直接复制
                public static void main(String[] args) throws IOException {
        		FileReader r = new FileReader("F:\test.py");
        		FileWriter w = new FileWriter("D:\test\test2.py");
        //		char[] buf = new char[1024];
        		int c ;
        		while((c=r.read())!=-1) {
        			w.write(c);
        		}
        		r.close();
        		w.close();
        	}    
        

          

  • 相关阅读:
    Linux文件与文件系统的压缩
    Linux命令与文件查找
    js兼容pc和移动端的简单拖拽效果
    图片懒加载插件
    css小特效
    创建对象和方法
    距离2021年春节还剩。。。
    固定尺寸的图片焦点图案例
    数据库操作
    简单sql操作
  • 原文地址:https://www.cnblogs.com/qf123/p/8534417.html
Copyright © 2011-2022 走看看