將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