package com.company;
import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Main
{
public static void main(String[] args) throws IOException
{
File f = new File("D:/1.txt");
FileReader fr = new FileReader(f);
BufferedReader br = new BufferedReader(fr);
List<String> list = new ArrayList<String>();
int Linenum = 1;
String s = null;
while ((s = br.readLine()) != null)
{
list.add(s);
}
System.out.println("输入要查找的单词");
Scanner sc = new Scanner(System.in);
String strWord = sc.nextLine();
for (String b : list)
{
boolean a = ContainsStr(b,strWord);
if(a){
System.out.println(Linenum+" "+b);
}Linenum++;
}
}
public static boolean ContainsStr(String s1, String s2)
{
if (s1.indexOf(s2) >= 0)
{
return true;
} else
{
return false;
}
}
}
import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Main
{
public static void main(String[] args) throws IOException
{
File f = new File("D:/1.txt");
FileReader fr = new FileReader(f);
BufferedReader br = new BufferedReader(fr);
List<String> list = new ArrayList<String>();
int Linenum = 1;
String s = null;
while ((s = br.readLine()) != null)
{
list.add(s);
}
System.out.println("输入要查找的单词");
Scanner sc = new Scanner(System.in);
String strWord = sc.nextLine();
for (String b : list)
{
boolean a = ContainsStr(b,strWord);
if(a){
System.out.println(Linenum+" "+b);
}Linenum++;
}
}
public static boolean ContainsStr(String s1, String s2)
{
if (s1.indexOf(s2) >= 0)
{
return true;
} else
{
return false;
}
}
}