---
title: "复制文件"
author: "wangyun"
date: "2008-04-14T20:53:56Z"
tags: []
slug: "untitled"
draft: false
lastmod: "2008-04-14T20:53:56Z"
id: 182704
url: "https://wangyun.iteye.com/blog/182704"
---

public class FileUtil {

	/**
	 *  复制文件
	 *  @param from 原文件
	 *  @param to 目标文件 
	 */
	public static void copyFile(String from, String to)
			throws  FileNotFoundException, IOException {
		FileChannel
			fChannel = new FileInputStream(from).getChannel(),
			tChannel = new FileOutputStream(from).getChannel();
		
		fChannel.transferTo(0, fChannel.size(), tChannel);
		//或者tChannel.transferFrom(fChannel, 0, fChannel.size());
	}
}