2

I would like to ask, how can i parse text. I had extracted text from PDF file with PDFBox into normal text, which is output in console. For example this one:

SHA256: 51c11994540537b633cf91b276b3c34556695ed870a5d3f7451e993262a4a745
File name: ACleaner.zip
Detection ratio: 0 / 55
Analysis date: 2015­07­21 12:23:19 UTC ( 8 minutes ago )
0 0
? Analysis ? File detail ? Additional information ? Comments  0 ? Votes
MD5  fffa183f43766ed39d411cb5f48dbc87
SHA1  b0d40fbc6c722d59031bb488455f89ba086eacd9
SHA256  51c11994540537b633cf91b276b3c34556695ed870a5d3f7451e993262a4a745

I need to get some values, for example value of MD5, File name etc..how can i reach it in Java? Thanks a lot


I have tried so : in this while a i added this

String keySHA256 = "SHA256:";
private static String SHA256Value = null;

if (line.contains(keySHA256)) {
    //  System.out.println(line);
    int length = keySHA256.length();
    SHA256Value = line.substring(length);
    System.out.println("SHA256 >>>>" + SHA256Value);
}

but sometimes it doesnt get right value..please help..

ChrisF
  • 134,786
  • 31
  • 255
  • 325
YouYyn
  • 229
  • 1
  • 2
  • 7

1 Answers1

2

This could be a good example for you to start learning more about Java IO and String parsing. Google is your friend.

//uri where your file is 
String fileName = "c://lines.txt";
// read the file into a buffered reader
try (BufferedReader br = new BufferedReader(new FileReader(fileName))) {

    String line;
    while ((line = br.readLine()) != null) { //iterate on each line of the file
        System.out.println(line); // print it if you want 
        String[] split=line.split(" "); // split your line into array of strings, each one is a separate word that has no spaces in it.
        //add any checks or extra processes here 
    }

} catch (IOException e) {
    e.printStackTrace();
}
Mohamed Taher Alrefaie
  • 15,698
  • 9
  • 48
  • 66