hi,
i need a code that can read a character in the file. The example file is like this:
Then, i will read that file(above) and then get the request word until before the response. Then get the response until before the word successful.The quick brown fox,,,
field 1, 344
request: 12344 fjsdlfkj
bit 1
bit 2
fields2
response fkljsdfljewir
bit 1
bit 2
bit 3
successfull
request
bit 1
bit 2
response
failed
But my code below only shows per line basis not per word or character. please help me.
Sample output is like this:
request: 12344 fjsdlfkj
bit 1
bit 2
fields2
response fkljsdfljewir
bit 1
bit 2
bit 3
=====import java.awt.image.DataBuffer; import java.io.BufferedReader; import java.io.FileReader; import java.util.ArrayList; public class ReadFile { private String fileName = null; private int bufferSize = 1000; public ReadFile () {} public ReadFile (String fileName, int bufferSize) { this.setFileName (fileName); this.setBufferSize (bufferSize); } public ReadFile (String fileName) { this(fileName, 1000); } public void setFileName (String fileName) { this.fileName = fileName; } public String getFileName () { return this.fileName; } public void setBufferSize (int bufferSize) { this.bufferSize = bufferSize; } public int getBufferSize () { return this.bufferSize; } public ArrayList read () throws java.io.FileNotFoundException, java.io.IOException { FileReader fr = new FileReader (this.getFileName()); BufferedReader br = new BufferedReader (fr); ArrayList aList = new ArrayList (this.getBufferSize()); String line = null; while ( (line = br.readLine()) != null) { aList.add(line); } br.close(); fr.close(); return aList; } public static void main (String args[]) //include main for testing purposes { try { ReadFile rf = new ReadFile("C:\\txn.log"); ArrayList a = rf.read(); if (a.size() > 0) { int i, x; for (i=0; i<a.size(); i++) { if(a.contains("request")) { String test = (String) a.get(i+1); System.out.println (test); } } System.out.println ("EOF"); } } catch (Exception e) { System.out.println (e.getMessage()); } } }