hello all ,
from the string "MRN 09DE588004180289E0" i have to extract only the 18 digit number after MRN . this is actually present in a output.
doc file . I am currently not able to extract that from the file even after using file writer .
when i run no output is coming and output should actually be 09DE588004180289E0 on the command prompt
could anyone please help me out
that 18 is fine but here the problem is i have to read the value fom a text output.doc file such that if i enter search string only MRN it should output to me the "09DE588004180289E0" on the command prompt . i have used filereader but still dont know the reason why it is not showing the ouput .
1. //package com.test.pdf;
2.
3. //package jPDFTextSamples;
4.
5. import java.io.FileWriter;
6. import java.io.File;
7. import java.io.FileInputStream;
8. import java.io.IOException;
9. import java.io.InputStream;
10. import java.io.Reader;
11. import java.io.StringReader;
12. import java.util.Date;
13. import java.lang.String; //import org.pdfbox.util.TextPosition;
14. import java.io.*;
15. import java.lang.*;
16.
17. import java.io.FileNotFoundException;
18. import java.nio.ByteBuffer;
19. import java.nio.channels.FileChannel;
20. import java.util.regex.*;
21. import java.nio.*;
22. import java.nio.channels.*;
23. import java.nio.charset.*;
24.
25. //import com.qoppa.pdfText.PDFText;
26.
27. public class ExtractAllText2 {
28. public static void main(String[] args) {
29. try {
30. // Load the document
31. // PDFText pdfText = new PDFText ("Exportbegleitdokument.pdf",
32. // null);
33.
34. // Get the text for the document
35. // String docText = pdfText.getText();
36.
37. /*
38. * // Save the text in a file FileWriter output = new FileWriter
39. * ("output.doc"); output.write(docText); output.close();
40. *
41. * //want user to enter the string to extract File file = new
42. * File("output.doc");
43. */
44. // ....................................................
45. BufferedReader bf = new BufferedReader(new FileReader("d:\\output.doc"));
46. int linecount = 0;
47.
48. String line="";
49. boolean isWordMatched = false;
50.
51.
52.
53. String value = "";
54. String search = "MRN";
55.
56. while ((line = bf.readLine()) != null) {
57.
58. if (line.indexOf(search) != -1) {
59.
60. int valStartIndex = line.indexOf(search) + search.length()+ 1;
61.
62. int valEndIndex = line.indexOf(search) + search.length()+ 1 + 18;
63.
64. value = line.substring(valStartIndex, valEndIndex);
65.
66. isWordMatched = true;
67.
68. System.out.println("value>>>>:" + value);
69.
70. }
71.
72. }
73.
74.
75. } catch (Throwable t) {
76. t.printStackTrace();
77. }
78. }
79. }