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

📄 readfile.java

📁 jsp动态网站开发技术与实践 电子工业出版社 随书附赠源代码
💻 JAVA
字号:
package com.chapter4;

import java.io.*; 
import java.util.StringTokenizer; 

public class ReadFile 
{ 
	//类成员变量
	private String currentRecord; 
	private BufferedReader file; 
	private String path; 
	private StringTokenizer token;
	
	//建立文件对象
	public int createFileObj(String filePath) 
	{ 
		int i = 0;
		path = filePath; 
		try 
		{ 
			file = new BufferedReader(new FileReader(path)); 
		}
		catch (FileNotFoundException e)
		{ 		
			i = -1;
		} 
		
		return i;
	} 
	
	//得到文件路径 
	public String getPath() 
	{ 
		return path; 
	}		

	//读取下一行记录,若没有则返回-1 
	public int nextRecord() 
	{
		int i = -1; 
		try 
		{ 
			currentRecord = file.readLine(); 
		} 
		catch (IOException e) 
		{ 
			System.out.println("读取文件内容失败!"); 
		} 
		
		if (currentRecord == null) 
		{
			i = -1; 
		}
		else 
		{ 
			token = new StringTokenizer(currentRecord); 
			i = token.countTokens(); 
		} 
		
		return i; 
	} 
	
	//以字符串的形式返回某行数据 
	public String returnRecord() 
	{ 
		return currentRecord; 
	} 
	
	//关闭文件流 
	public void close() throws IOException 
	{ 
		file.close(); 
	} 
} 

⌨️ 快捷键说明

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