将java的关键字保存在一个文件中,编写程序判断一个字符串是否为java关键字

[复制链接]
查看11 | 回复1 | 2011-4-12 12:52:10 | 显示全部楼层 |阅读模式
回复

使用道具 举报

千问 | 2011-4-12 12:52:10 | 显示全部楼层
<pre id=\"best-answer-content\" class=\"reply-text mb10\">JavaHotKeyChecker.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 JavaHotKeyChecker {
public static void main(String[] args) throws IOException {
boolean yon = doCheck(\"class\");
if(yon) {
System.out.println(\"yes\");
} else {
System.out.println(\"no\");
}
}

private static boolean doCheck(String input) throws IOException {
boolean isHotKey = false;
File file = new File(\"D:/javahotkey.txt\");
String content = \"\";
FileReader fr = new FileReader(file);
BufferedReader br = new BufferedReader(fr);
String temp;
while (null != (temp = br.readLine())) {
content= temp;
}
String[] keys = content.split(\",\");
ListString keyList = new ArrayListString();
for (String key : keys) {
keyList.add(key.trim());
}
isHotKey = keyList.contains(input);
return isHotKey;
}
}


javahotkey.txt:
=================
public,static,void,class,interface,final,finally,catch,try
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行