Regex on whole (large) text file
From: Rune Johansen (rune[insert_current_year_here)
Date: 06/27/04
- Next message: Sophie Williams: "Eclipse Training"
- Previous message: Kova: "Re: jar archive"
- Next in thread: Raymond DeCampo: "Re: Regex on whole (large) text file"
- Reply: Raymond DeCampo: "Re: Regex on whole (large) text file"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sun, 27 Jun 2004 14:02:38 +0200
Hi,
I'm sorry if these questions are trivial, but I've searched the net and
haven't had any luck finding the information I need.
I need to perform some regular expression search and replace on a large
text file. The patterns I need to match are multi-line, so I can't do it
one line at a time. Instead I currently read in the entire text file in
a string using the code below.
File fin = new File("input.txt");
FileInputStream fis = new FileInputStream(fin);
BufferedReader in = new BufferedReader(new InputStreamReader(fis));
String aLine = null;
String theText = "";
while((aLine = in.readLine()) != null) {
theText = theText + aLine + "\n";
}
The problem with this is that the first couple of thousand lines read in
very fast, but it gets slower and slower, and as we approach line 4000
it gets really slow per line.
Is there a better way to read in an entire text file into a string?
Is storing the entire text file in a string a bad idea? And if so, what
are the alternatives?
Is it possible to perform multiple-line regular expressions on a text
file without loading the whole text file into memory?
Thanks in advance,
Rune
- Next message: Sophie Williams: "Eclipse Training"
- Previous message: Kova: "Re: jar archive"
- Next in thread: Raymond DeCampo: "Re: Regex on whole (large) text file"
- Reply: Raymond DeCampo: "Re: Regex on whole (large) text file"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|