자바 바이트 흐름 파일 복사 작업

1464 단어 JavaSE

	public static void main(String[] args) throws IOException {
		//copyFileOne();//  ,     ,           ,   
		copuFileTwo();//     330ms    
	}
	/**
	 * read(byte[] b)
	 *    read()     
	 *         ,     1024                   ,                 ,        
	 */
	private static void copuFileTwo() throws IOException{
		long begin = System.currentTimeMillis();
		FileInputStream fis = new FileInputStream("D:\\test.avi");
		FileOutputStream fos = new FileOutputStream("F:\\test.avi");
		byte[] b = new byte[1024];
		int len = 0;
		while((len = fis.read(b)) != -1){
			fos.write(b);
		}
		fis.close();
		fos.close();
		System.out.println("      ,  :" + (System.currentTimeMillis() - begin) + "ms");
		
	}
	/**
	 * read();       ,      
	 *          ,       ,  ,  ,mp3 
	 * 1.    
	 * 2.              
	 * 
	 *             ,           ,     3 try..catch,    ,    
	 */
	private static void copyFileOne() throws IOException{
		long begin = System.currentTimeMillis();
		File file = new File("D:\\test.avi");//    27.9M    292708000s,      ,27M         ,               ....
		FileInputStream fis = new FileInputStream(file);
		FileOutputStream fos = new FileOutputStream("F:\\test.avi");
		int len = 0;
		while((len = fis.read()) != -1){
			fos.write(len);//    
		}
		fis.close();
		fos.close();
		System.out.println("      ,  :" + (System.currentTimeMillis() - begin) + "ms");
	}

좋은 웹페이지 즐겨찾기