将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;
}
}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM