Manipulating text file
I have a text file that look something like this:
[21/06/07] System DEBUG * BA_LOG_OUTPUT
System DEBUG Random text Random text
System DEBUG Random text Random text
System DEBUG Random text Random text
System DEBUG Random text Random text <?xml version=?.0?encoding=擴FT-8?>
<?xml version="1.0" encoding="UTF-8"?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
[21/06/07] System DEBUG * BA_LOG_OUTPUT
System DEBUG Random text Random text
System DEBUG Random text Random text
System DEBUG Random text Random text
System DEBUG Random text Random text <?xml version=?.0?encoding=擴FT-8?>
<?xml version="1.0" encoding="UTF-8"?>
<note>
<to>Tony</to>
<from>James</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
[21/06/07] System DEBUG * BA_LOG_OUTPUT
System DEBUG Random text Random text
System DEBUG Random text Random text
System DEBUG Random text Random text
System DEBUG Random text Random text <?xml version=?.0?encoding=擴FT-8?>
<?xml version="1.0" encoding="UTF-8"?>
<note>
<to>Amy</to>
<from>Tobi</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
I am trying to read the file so that it picks the welled formed XML e.g:
<?xml version=?.0?encoding=擴FT-8?>
<?xml version="1.0" encoding="UTF-8"?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
<?xml version=?.0?encoding=擴FT-8?>
<?xml version="1.0" encoding="UTF-8"?>
<note>
<to>Tony</to>
<from>James</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
<?xml version="1.0" encoding="UTF-8"?>
<note>
<to>Amy</to>
<from>Tobi</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
There is a pattern in the file, the line <?xml version=?.0?encoding=擴FT-8?>
Always start on the 4th line after BA_LOG_OUTPUT line
This is my code so far:
BufferedReader in =new BufferedReader(new FileReader(file));
String line =null;
Pattern p = Pattern.compile( 揃A_LOG_OUTPUT?);
StringBuffer sb =new StringBuffer();
while((line = in.readLing()) !=null){
Matcher m = p.matcher(line);
while(m.find()){
System.out.println( line );
}
}
How do I make it so it goes 4 line down so it can find the line <?xml version=?.0?encoding=擴FT-8?> and start reading the xml file?

