import java.io.*;import java.util.Vector;import java.util.regex.Pattern; class FileRead { public static void main(String args[]) { try{ // Open the file that is the first // command line parameter FileInputStream fstream = new FileInputStream("c:\\shoutin.txt"); // Get the object of DataInputStream DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String strLine; Vector<String> fileVector = new Vector<String>(); //Read File Line By Line while ((strLine = br.readLine()) != null) { // Print the content on the console // fileVector.add(strLine); //System.out.println (fileVector.elementAt(fileVector.size()-1)); } //Close the input stream in.close(); Vector<Integer> entryLine = new Vector<Integer>(); for(int i=fileVector.size()-1; i>=0 ;i--){ String regex=".*February 2010.*"; String currentLine=fileVector.elementAt(i); boolean isMatch = Pattern.matches(regex,currentLine); if (isMatch){ entryLine.add(i-1); } } int entryEnd=(Integer)fileVector.size(); for(int i=0;i<(Integer)entryLine.size()-1;i++){ int entry=(Integer)entryLine.elementAt(i); System.out.println("[quote="+(String)fileVector.elementAt(entry)+ " - " + (String)fileVector.elementAt(entry+1)+"]"); for (int l=entry+2;l<entryEnd;l++){ System.out.println("\t"+(String)fileVector.elementAt(l)); } int nextEntry=(Integer)entryLine.elementAt(i+1); entryEnd = nextEntry+(entry-nextEntry); System.out.println("[/quote]"); } }catch (Exception e){//Catch exception if any System.err.println("Error: " + e.getMessage()); } }}