怎样读取文件内容到指定行后再存储文件的内容 比如一个文件内容为:sada1231241241241asdasaaaaassssvvvvbbbb现在我想读取到aaaaa这行以后,再将剩下的内容存储到arraylist中。。请问该怎么解决 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 建议楼主可以试着写一些代码(就是简单的读文件,然后处理读到的内容)这样就算最后没有成功,把错误代码贴出来,让大家帮忙看看,收获会更多,下面可以参考下public static void main(String[] args)throws IOException{ //指定字符串 String str="aaaaa"; //待读取的文件 String file="F:/test.txt"; List<String> list= filterFileContent(str,file); System.out.println(list); } public static List<String> filterFileContent(String str,String file) throws IOException { //储存指定字符串后内容的List List<String> list = new ArrayList<String>(); //是否读到了指定的字符串处 int flag=0; BufferedReader in = null; try { in = new BufferedReader(new InputStreamReader( new FileInputStream(file), "utf-8")); String line; while( (line=in.readLine())!=null){ if(flag==1){ list.add(line); } if(line.equals(str)){ flag=1; } } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally{ in.close(); } return list; } java object数组显示异常 java中有类似visual assist的工具吗? 问一个有挑战性的SQL问题 如何理解for (Iterator <Entry <UpdateVO, List <UpdateVO>>> 希望这个问题能在CSDN网站上帮我解决. 请教JSF里复选框的选定问题 一个JAVA新手的困惑,希望高手指点迷津 如何写判断一个字符串是否符合一个四则运算式的正则表达式 JAVA处理DB2数据的问题! 请问有关RMI和网络编程的问题!立即给分! 一个非常典型的乱码问题 Thinking in java 里并发 join()的问题
public static void main(String[] args)throws IOException{
//指定字符串
String str="aaaaa";
//待读取的文件
String file="F:/test.txt";
List<String> list= filterFileContent(str,file);
System.out.println(list);
}
public static List<String> filterFileContent(String str,String file) throws IOException {
//储存指定字符串后内容的List
List<String> list = new ArrayList<String>();
//是否读到了指定的字符串处
int flag=0;
BufferedReader in = null;
try {
in = new BufferedReader(new InputStreamReader( new FileInputStream(file), "utf-8"));
String line;
while( (line=in.readLine())!=null){
if(flag==1){
list.add(line);
}
if(line.equals(str)){
flag=1;
}
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
finally{
in.close();
}
return list;
}