2016-02-10 32 views
1

我想問一下,我如何解析文本。我用PDFBox將PDF文件中的文本解壓縮爲普通文本,並在控制檯中輸出。例如,這一個:從PDF解析文本Java

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 

我需要得到一些值,MD5的值例如,文件名我etc..how可以用Java實現它?非常感謝


我已經試過這樣:在此同時,AI加入這個

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); 
} 

但有時它沒有得到正確的value..please幫助..

回答

1

這可能是一個很好的示例讓您開始學習更多關於Java IO和String解析的知識。 Google是你的朋友。

//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(); 
} 
+0

'BufferedReader'不會爲'.pdf's –

+0

是thanks..but我怎麼能在我的情況下獲得例如文件名中的值工作?...非常感謝 – YouYyn

+0

,但我不得不解析它成正常的文字... – YouYyn