+ -
当前位置:首页 → 问答吧 → 字符串匹配问题

字符串匹配问题

时间:2011-12-12

来源:互联网

代码是这样的:
public void display() throws IOException{

System.out.print("Enter keyword:");
Scanner scan = new Scanner(System.in);
String s =scan.nextLine();
//System.out.println(s.toString());

BufferedReader in = new BufferedReader(new InputStreamReader(
new FileInputStream("d:/record.txt")));

  String line = null;
  while((line=in.readLine())!=null){
  if(line.contains(s));
  {System.out.println(line.toString());
  }}
意思是这样:
随便输入一个字符串s,看它是否是字符串line的子字符串,若是,这输出line字符串。line字符串是txt文件里一堆的记录。

作者: cy_name   发布时间: 2011-12-12

出错的原因是它没有任何选择的把txt文件里的记录全输出了。

作者: cy_name   发布时间: 2011-12-12

没有看出来有什么问题哦

作者: Judy1990   发布时间: 2011-12-12

热门下载

更多