JAVA 复制图片实例

 

    /**
     * 功能: 拷贝image从一个地址至另一个地址
     * @param sourcePath 
     * 				图片初始生成地址
     * @param toPath
     * 				图片要复制到的地方
     * @param FileName
     * 				图片的名字
     * @param FileN
     * 				生成的文件夹名字
     */
    public void copyToOtherPath(String sourcePath,String toPath,String FileName,String FileN){
		try {
			File toFile=new File(toPath+FileName+"//"+FileN);
			if(!toFile.exists())
				toFile.mkdirs();
			FileChannel srcChannel = new   FileInputStream(sourcePath).getChannel();
	        FileChannel   dstChannel   =   new   FileOutputStream(toPath+FileName+"//"+FileN+"//"+FileName+".JPEG").getChannel(); 
	        dstChannel.transferFrom(srcChannel,0,srcChannel.size()); 
	        srcChannel.close(); 
	        dstChannel.close();
		} catch (Exception e) {
			e.printStackTrace(); 
		}
       
    }

你可能感兴趣的:(java,File,图片复制,FileChannel,JAVa复制图片)