java 如何读取包含指定字符串的行(txt文件) 如题,谢谢。最好能有例子源码啊 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 用BufferedReader的readLine方法,读出来以后判断是否包含,若包含取行号就行啊。 import java.io.BufferedReader;import java.io.File;import java.io.FileReader;import java.io.IOException;import java.util.ArrayList;import java.util.List;public class IsContain{ /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { List<Integer> lstIndex = new ArrayList<Integer>(); String atoi = "abc"; BufferedReader br = new BufferedReader(new FileReader(new File( "d:/text.txt"))); String s = ""; int index = 0; while ((s = br.readLine()) != null) { index++; if (s.contains(atoi)) { System.out.println(index); lstIndex.add(index); } } br.close(); }} Thinking in Java里的一个包 如何实现限制调用类中的某个方法的频率? 如何成为一名java程序员 关于类继承时方法和属性的问题 一个字符串输出 如何进行汉字的提取(顺便介绍个群:程序员朋友7213300) 菜鸟问关于java开发工具的问题 怎样用java实现网络封包监控啊 java或是jsp怎么连接LDAP,并对LDAP数据进行操作,急,在线等~~~~~~分数好说 100分求关于Assertion的一切资料!!! 【散分】进者有分 oracle
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;public class IsContain
{ /**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException
{
List<Integer> lstIndex = new ArrayList<Integer>();
String atoi = "abc";
BufferedReader br = new BufferedReader(new FileReader(new File(
"d:/text.txt")));
String s = "";
int index = 0;
while ((s = br.readLine()) != null)
{
index++;
if (s.contains(atoi))
{
System.out.println(index);
lstIndex.add(index);
}
}
br.close();
}
}