Representing a text file as single unit in Java, and matching strings in the text -
How can I represent a text file (or XML file) as a whole string, and (or match) Search for is a special string in it?
I have created a buffer reader object:
BufferedReader input = new BufferedReader (New FileReader (aFile)); And then I have tried using the scanner class to specify different delimiters, such as:
// Scanner scantext = new scanner (input); // scanner scantext = new scanner (input). Use delimiter (""); Scanner Scanctect = New Scanner (Input). Use delimiter ("\ n"); While (scantext.hasNext ()) {...} By using scanner class like this, I can either read the text line through the line, or word by word, but it Do not help me, because sometimes in the text, which I want to process, I have
& lt; / Review & gt; & Lt; Review & gt; And I would like to say: If you get " " anywhere in the text, then the following rows (or piece of piece) Lesson) until you find " ". The problem is that & lt; Review & gt; and & lt; / Review & gt; is in different places in the text, and sometimes sticks to other text (hence the empty space in the delimiter), I have not been able to help.
I have thought that I can use the regular expression API in Java (Pattern and Matter sections), but they match a particular string or line, and I want to have a continuous string form In the text (at least this, what I read from them about my impressions) can you tell me which methods / methods / classes should I use in this matter? Thank you.
Do not try to parse XML with regular expressions; It is only for pain, there are so many very good in Java;
- Load the file as a string
Comments
Post a Comment