具体实现
//读取一个文本的字符流
BufferedReader in = new BufferedReader(new FileReader("F:\\json.txt"));
String line = null;
//定义一个空字符串来接受读到的字符串
String str="";
//循环把读取到的字符赋给str
while((line = in.readLine())!=null)
{
str+=line;
}
System.out.println("str="+str);
//判断str中是否有EFG子串,为true则说明有。进去if语句
if(str.contains("EFG")){
System.out.println("yes!");
//取得子串的初始位置
int i=str.indexOf("EFG");
//根据的要取的内容后多少字符+多少个
String strEFG=str.substring(i,i+3);
System.out.println("strEFG="+strEFG);
}
追问我是要取包含字符的那一整行呀