readLine

/*
通过缓冲区赋值一个.java文件
readLine方法只返回回车前面的内容,不返回回车符
*/
import java.io.*;
class BufferedDemo
{
	public static void main(String[] args) 
	{
		BufferedWriter buffWriter = null;
		BufferedReader buffReader = null;
		try
		{
			buffWriter = new BufferedWriter(new FileWriter("bufCopy.txt"));
			buffReader = new BufferedReader(new FileReader("buf.txt"));
			String line = null;
			while((line = buffReader.readLine()) != null)
			{
				buffWriter.write(line);
				buffWriter.newLine();
				buffWriter.flush();
			}
		}
		catch (IOException ex)
		{
			System.out.println(ex.getMessage());
		}
		finally
		{
			try
			{
				if(buffWriter != null)
				{
					buffWriter.close();
				}
				if(buffReader != null)
				{
					buffReader.close();
				}
			}
			catch (IOException ex)
			{
				System.out.println(ex.getMessage());
			}
		}
	}
}

posted @ 2015-01-14 22:11  静以养身 俭以养德  阅读(194)  评论(0编辑  收藏  举报