现在的位置: 首页 > 综合 > 正文

《java—-IO流—文件复制》

2013年07月28日 ⁄ 综合 ⁄ 共 455字 ⁄ 字号 评论关闭
import java.io.FileReader;
import java.io.FileWriter;

class IOTest 
{
	public static void main(String[] args)
	{
		FileReader fr = null;
		FileWriter fw = null;
		try
		{
			fr = new FileReader("EditPlus.txt");
			fw = new FileWriter("MYIOEditPlus.txt");

			char [] cbuf = new char [1024];
			int len = 0;
			
			while((len = fr.read(cbuf)) != -1)
			{
				fw.write(cbuf, 0, len);
			}
		}
		catch (Exception e)
		{
			throw new RuntimeException("文件读取失败!"); 
		}
		finally
		{
			if(fr != null)
				try
				{
					fr.close();
				}
				catch (Exception e)
				{
				}
				if(fw != null)
				try
				{
					fw.close();
				}
				catch (Exception e)
				{
				}	
		}
	}
}

抱歉!评论已关闭.