package com.lianxi;
import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
/**
* Created by ttc on 16-10-31.
*/
public class Main
{
public static void main(String[] args) throws IOException
{
File f=new File("E:/code.txt");
FileReader fr=new FileReader(f);
BufferedReader br=new BufferedReader(fr);
String strRead =null;
List<String> lstLines=new ArrayList<String>();
int nLinNum=1;
while ((strRead=br.readLine())!=null)
{
System.out.println(nLinNum+":"+strRead);
nLinNum++;
}
System.out.println("请输入字符串");
Scanner sc=new Scanner(System.in);
String strWord=sc.nextLine();
for(String strTemp: lstLines)
{
boolean b=containsstr(strTemp,strWord);
if(b)
{
System.out.println(nLinNum+":"+strTemp);
}
nLinNum++;
}
}
public static boolean containsstr(String s1,String s2)
{
if(s1.indexOf(s2)>=0)
{
return true;
}else
return false;
}
}
查询一段字符串在文章中的位置
最新推荐文章于 2022-01-12 15:30:01 发布