-3

I am reading a file. I need to convert each value to java object.

String sCurrentLine;
BufferedReader br = null;
int pointer = 1;
try {
    br = new BufferedReader(new FileReader("src/main/java/com/ali/trillium/p0f.log"));
} catch (FileNotFoundException e) {
    e.printStackTrace();
}
while ((sCurrentLine = br.readLine()) != null) {
    System.out.println(sCurrentLine);
    System.out.println("---------------");
    System.out.println(pointer++);
    System.out.println("---------------");
}

Output of program

<Tue Apr 10 09:21:42 2018> 172.20.16.36:62385 - Windows XP/2000 (RFC1323+, w+, tstamp-) (ECN) [low cost] [GENERIC] Signature: [8192:113:1:52:M1352,N,W8,N,N,S:.:Windows:?] -> 172.20.16.23:3391 (distance 15, link: unknown-1392)
Federico klez Culloca
  • 22,898
  • 15
  • 55
  • 90
  • 1
    @KamranKhan you have a lot of good suggestions in the comments. Take every topic mentioned and read up on it. I get the feeling you should spend more time learning the language. Sit down and read stuff – Neuron Apr 17 '18 at 12:32
  • possible duplicate of https://stackoverflow.com/questions/18607418/how-to-split-the-strings-in-a-file-and-read-them/18607545#18607545 – Digao Apr 17 '18 at 13:30
  • Possible duplicate of [How to split the strings in a file and read them?](https://stackoverflow.com/questions/18607418/how-to-split-the-strings-in-a-file-and-read-them) – Rann Lifshitz Apr 18 '18 at 09:20
  • Kamaran Khan: Please consider selecting the only answer to this question as the selected right answer. Thanks you for your time and I hope the answer was helpful to you. – Rann Lifshitz May 05 '18 at 04:36

1 Answers1

1

Like Lonely Neuron suggested :

You should use delimiting libraries in order to parse your output into a working data structure. You can use the split function to achieve this:

s.split("delimiter"); // replace delimiter with the actual delimiting in the output

Please note that the parameter of split is a regex expression, so be cautious with passing things like ".". Assuming you have a multiple line output - you may want to use multiple calls to the split method.

There are numerous ways to perform delimiting in java: you can use a Scanner, or a StringTokenizer (second answer) as well.

Good Luck!

Rann Lifshitz
  • 3,862
  • 4
  • 18
  • 40