Posted By:
Shahmil_Merchant
Posted On:
Wednesday, August 14, 2002 12:00 PM
i have a file from which i have to read data.The file has lines in between such as == or % I tried defining 2 pattern matchers Pattern p = Pattern.compile("[==\n]+"); Matcher matcher = p.matcher(""); Pattern p1 = Pattern.compile("[%\n]+"); Matcher m = p1.matcher(""); I read one line at a time and put it into a map/vector as per required while((aLine = in.readLine()) != null) { matcher.reset(aLine); m.reset(aLine); if (matcher.find()) { // line matches the pattern if (aLine != null){ if (term.size() > 0){ map.put(record,term); } r
More>>
i have a file from which i have to read data.The file has lines in between such as
== or
%
I tried defining 2 pattern matchers
Pattern p = Pattern.compile("[==\n]+");
Matcher matcher = p.matcher("");
Pattern p1 = Pattern.compile("[%\n]+");
Matcher m = p1.matcher("");
I read one line at a time and put it into a map/vector as per required
while((aLine = in.readLine()) != null) {
matcher.reset(aLine);
m.reset(aLine);
if (matcher.find()) {
// line matches the pattern
if (aLine != null){
if (term.size() > 0){
map.put(record,term);
}
record = aLine;
term = new Vector();
}
}
if (m.find()) {
// line matches the pattern
if (aLine != null) {
term.addElement(aLine);
somwhow when i run the code i print out just
==
or %
instead of the values after == and %
i tried using
in my pattern matcher instead of \n but to the same probem.
My file as i said earlier is in the following format
==
xxxxxxxxxxxxxx
%
xxxxxxxxxx
==
i want to obviously read the XXX.Defining both the patterns in one matcher didnt help
<<Less