Extract a portion from a text-file

P

Prabh

Hi,
Could anyone tell me how to do this in Java, please.
I need to extract a portion of a file.

File:
================================================
line1
line2
line3
Property1 = value1\
value2\
value3

line4
line5
================================================

I'd like to extract the "Property-value" portion.
Could someone give me any pointers, please.

For what its worth, I'd do this Perl as:
while (<>) {
print if (/^Property1(.*)$/ .. /^$/) =~ /^\d+$/;
}

Thanks,
Prabh
 
W

Weichao Wang

import java.io.*;
.......
try {
BufferedReader f = new BufferedReader(
new FileReader(theFileName)
);
String line;
while ((line = f.readLine()) != null)
if (line.startsWith("Property"))
System.out.println(line);
} catch (Exception e) {
System.out.println(e.toString());
}
.......
I haven't tested it. The logic must be so.

Weichao
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top