zoukankan      html  css  js  c++  java
  • java高级程序设计(第四周)

    本次作业实现了文件的拷贝,通过修改一次读取写入字节实现了快速拷贝。
    package copy;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.IOException;

    public class copy {
    /**
    * @param args
    */

    public static void main(String[] args) {
    	
    	long startTime = System.currentTimeMillis();//获取当前时间
    	try {
    		FileInputStream fis = new FileInputStream ("a.mp3");
    		FileOutputStream fos = new FileOutputStream ("temp.mp3");
    		int read = fis.read();
    		 byte[] b = new byte[1024*100]; 
    		 int len; 
    		 while ( (len = fis.read(b)) != -1) { 
    		 fos.write(b, 0, len); 
    		 }
    

    // while ( read != -1 ) {
    // fos.write(read);
    // read = fis.read();
    // }
    fis.close();
    fos.close();
    } catch (IOException e) {
    e.printStackTrace();

    	}
    long endTime = System.currentTimeMillis();
    System.out.println("运行时间:"+(endTime-startTime)+"ms");
    		}
    

  • 相关阅读:
    Root of AVL Tree
    04-树4 是否同一棵二叉搜索树
    03-树3 Tree Traversals Again
    03-树2 List Leaves
    283. Move Zeroes
    506. Relative Ranks
    492. Construct the Rectangle
    476. Number Complement
    461. Hamming Distance
    389. Find the Difference
  • 原文地址:https://www.cnblogs.com/2014330122wwh/p/5360258.html
Copyright © 2011-2022 走看看