Skip to main content

File read performance

1 reply [Last post]
jeremygwa
Offline
Joined: 2006-01-17

I need to read a text file with each line being added to an array list. What is the most optimal way to do this. here is an example of what I have so far.

try {
int len = (int)(new File(file).length());
FileInputStream fis =
new FileInputStream(file);
byte buf[] = new byte[len];
fis.read(buf);
fis.close();
new File(file).delete();
String raw = new String(buf);
String [] lines = raw.split("\\n");
for(int i=0;i

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
alexlamsl
Offline
Joined: 2004-09-02

[b]java.io.LineNumberReader[/b] should be of help here.