将Java的关键字保存在文本文档中。判断一个字符串是否为Java中的关键字

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class text {
private static BufferedReader bin;

public static void main(String[] args) throws IOException {
String s="public";
boolean you = doCheck(s);
if(you) {
System.out.println("Yes!");
} else {
System.out.println("No!");
}
}

private static boolean doCheck(String input) throws IOException {
boolean isKey = false;
File file = new File("D://javahotkey.txt");
String content = "";
FileReader fin = new FileReader(file);
bin = new BufferedReader(fin);
String temp;
while (null != (temp = bin.readLine())) {
content =content + temp+',';
}
String[] keys = content.split(",");
List<String> keyList = new ArrayList<String>();
for (String key : keys) {
keyList.add(key.trim());
}
isKey = keyList.contains(input);
bin.close();
fin.close();
return isKey;
}
}

posted @ 2017-12-29 17:42  wannur  阅读(2722)  评论(0编辑  收藏  举报