• (转) java 复制文件,不使用输出流复制,高效率,文件通道的方式复制文件


    public static void fileChannelCopy(File s, File t) {
    		
    		FileInputStream fi = null;
    		
    		FileOutputStream fo = null;
    		
    		FileChannel in = null;
    		
    		FileChannel out = null;
    		
    		try {
    			
    			fi = new FileInputStream(s);
    			
    			fo = new FileOutputStream(t);
    			
    			in = fi.getChannel();// 得到对应的文件通道
    			
    			out = fo.getChannel();// 得到对应的文件通道
    			
    			in.transferTo(0, in.size(), out);// 连接两个通道,并且从in通道读取,然后写入out通道
    			
    		} catch (IOException e) {
    			
    			e.printStackTrace();
    			
    		} finally {
    			
    			try {
    				
    				fi.close();
    				
    				in.close();
    				
    				fo.close();
    				
    				out.close();
    				
    			} catch (IOException e) {
    				
    				e.printStackTrace();
    				
    			}
    			
    		}
    		
    	}
    	
    

      

  • 相关阅读:
    frog-jump
    nth-digit
    binary-watch
    elimination-game
    evaluate-division
    random-pick-index
    integer-replacement
    rotate-function
    longest-substring-with-at-least-k-repeating-characters
    decode-string
  • 原文地址:https://www.cnblogs.com/jiayongchao/p/4010832.html
Copyright © 2020-2023  润新知