How to read the file section

Used to read the project file, but there are some very large files. Immediately added to the recycling of memory to take, efficiency is at the end, try to use sub-read, this method is feasible. Paste the code out, If you have a better way. Please correct me.

public static List <Keyword> readFile (int formIndex, int toIndex) (
List <Keyword> lists = new ArrayList <Keyword> ();
String path = getPadFilePath ();
try (
FileReader fr = new FileReader (path);
BufferedReader br = new BufferedReader (fr);

String temp;
int i = 0;
while ((temp = br.readLine ())! = null) (
i + +;
if (i> formIndex & & i <toIndex) (
lists.add (new Keyword (temp));
fr.close ();
) Catch (Exception e) (

log.error ( "read file exception:" + getExceptionStr (e));
return lists;

Note: fromIndex - the starting position. toIndex --- end of the position.

Previously, the practice is to use the List, there is a subList way, this can be achieved, but the aim is different. If that's the case. Done is very simple.

分类:Java 时间:2008-05-23 人气:279
blog comments powered by Disqus


  • Display the file name contains the string: grep-lr string path 2011-05-29

    Display the file name contains the string: grep -l -r String path

  • Displays the file name containing the string: grep-lr string path 2011-05-29

    Displays the file name containing the string: grep -l -r String path

  • The efficiency difference between String and StringBuffer 2010-03-29

    We are in the encoding process, there are many string-related operations, Basically, every java programmer knows String and StringBuffer two strings above, in dealing with the efficiency of large differences In the final analysis is a String is a one

  • PB to connect Access database, change the default path to the solution error 2010-03-17

    PB Internet connection Access Database in many not repeat A friend had encountered a problem, call getOpenFileName () and getSaveFileName () after Question 1: The database will be abnormal, suggesting that the database path is incorrect. Or Question

  • jxl operation excel (create, read) examples 2010-05-10

    package com.lll.test; import; import java.util.ArrayList; import java.util.List; import com.lll.util.Jobs; import com.lll.util.JobsDA; import jxl.Cell; import jxl.CellType; import jxl.DateCell; import jxl.NumberCell; import jxl.Sheet; im

  • Text clustering generated java implementation (2) 2011-04-12

    Oh, to continue. This section of the learning content: 4. The word from the remaining features to extract text, text that is most representative of the word 5. Using space vector representation of text, vector space to be standardized , Values ​​to b

  • 无法在PC上找到,android app 创建的文件 问题. 2013-08-08

    不用reboot就可以让数据出现的方法. As anyone who worked with android applications experienced, the files created by Android application in "External Storage" (I don't like this term, as this usually refers to internal memory of the device), do not show up in

  • 采集电子报纸 2015-04-07

    项目托管于Github 1.接口 /** *报纸采集器 * @author 杨尚川 */ public interface PaperCollector { /** * 下载当日报纸,一个文件对应一个版面 * @return 报纸 */ List<File> collect(); /** * 下载指定日期的报纸,一个文件对应一个版面 * @param date 指定日期 * @return 报纸 */ List<File> collect(Date date); } 2.抽象类 /

  • Large sites to achieve a record of user behavior - based on clickStream (Part I) 2010-03-29

    Large-scale Internet application records the user's behavior is a problem, how the user experience does not affect the case, the asynchronous tracking user behavior, apache open source project clickstream is a good choice, according to session creati

iOS 开发

Android 开发

Python 开发



PHP 开发

Ruby 开发






Javascript 开发

.NET 开发



Copyright (C), All Rights Reserved. 版权所有 闽ICP备15018612号

processed in 0.056 (s). 13 q(s)