⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 filereadertest.java

📁 疯狂Java讲义_源码(含Java设计模式CHM
💻 JAVA
字号:
import java.io.*;
/**
 * Description:
 * <br/>Copyright (C), 2005-2008, Yeeku.H.Lee
 * <br/>This program is protected by copyright laws.
 * <br/>Program Name:
 * <br/>Date:
 * @author  Yeeku.H.Lee kongyeeku@163.com
 * @version  1.0
 */
public class FileReaderTest
{
	public static void main(String[] args) throws IOException
	{
		FileReader fr = null;
		try
		{
			//创建字符输入流
			fr = new FileReader("FileReaderTest.java");
			//创建一个长度为32的“竹筒”
			char[] cbuf = new char[32];
			//用于保存实际读取的字符数
			int hasRead = 0;
			//使用循环来重复“取水”过程
			while ((hasRead = fr.read(cbuf)) > 0 )
			{
				//取出“竹筒”中水滴(字节),将字符数组转换成字符串输入!
				System.out.print(new String(cbuf , 0 , hasRead));
			}
		}
		catch (IOException ioe)
		{
			ioe.printStackTrace();
		}
		finally
		{
			//使用finally块来关闭文件输入流
			if (fr != null)
			{
				fr.close();
			}
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -