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 人气:261
分享到:
blog comments powered by Disqus

相关文章

iOS 开发

Android 开发

Python 开发

JAVA 开发

开发语言

PHP 开发

Ruby 开发

搜索

前端开发

数据库

开发工具

开放平台

Javascript 开发

.NET 开发

云计算

服务器

Copyright (C) codeweblog.com, All Rights Reserved.

CodeWeblog.com 版权所有 黔ICP备15002463号-1

processed in 0.140 (s). 12 q(s)