java我试图读取一个文本文件,找到特定的匹配项并打印出来,但我的代码不起作用
我把它放在查找字符串匹配项上,只是成功地显示build,没有其他内容。我把它放在查找字符串匹配项上,只是成功地显示build,没有其他内容。我把它放在查找字符串匹配项上,只是成功地显示build,没有其他内容
public class Lab1 {
public static final String FileName = "E:\\test\\new.txt";
public static void main(String[] args) {
BufferedReader br = null;
FileReader fr = null;
try {
fr = new FileReader(FileName);
br = new BufferedReader(fr);
String r = null;
r = br.readLine();
String key = "int, float, if, else , double";
String iden = "a, b, c, d, e , x , y , z";
String mat = "int, float, if, else , double";
String logi = "int, float, if, else , double";
String oth = "int, float, if, else , double";
if(r.contains(key)) {
System.out.println(key.matches(r));
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
# 1 楼答案
contains()不是这样工作的
你能做的是:
您不必为此使用正则表达式,只需执行以下操作: