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

📄 txtextractor.java

📁 一个用于搜索本地文件内容的小型搜索引擎
💻 JAVA
字号:
package invertedList;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;


public class TxtExtractor extends Extractor {

	@Override
	public String getInformation(File file) {
		try {
			BufferedReader buf = new BufferedReader(new FileReader(file));
			StringBuffer buffer = new StringBuffer();
			String temp = null;
			while((temp = buf.readLine())!= null){
				buffer.append(temp);
			}
			
			buf.close();
			return buffer.toString();//now the target contains all the text of the txt file

			
		} catch (FileNotFoundException e1) {
			System.out.println(file.getName() + " is not found.");
		} catch (IOException e2){
			System.out.println("Errors occur during " + file.getName() + " is read.");
		}
		return null; //return null if some errors occur.
	}
}

⌨️ 快捷键说明

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