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

转载于:https://www.cnblogs.com/wannur/p/8145645.html

  • 1
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值