欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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

程序员文章站 2024-03-04 16:50:23
...
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)
				{
				}	
		}
	}
}
《java----IO流---文件复制》