-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReadDocFile.java
63 lines (62 loc) · 2.55 KB
/
ReadDocFile.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package experion;
import java.io.*;
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.extractor.WordExtractor;
public class ReadDocFile
{
public static void main(String[] args)
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
File file = null;
WordExtractor extractor = null;
try
{
System.out.println("Enter the File directory:");
String dir=br.readLine().replace("\\","\\\\");
file = new File(dir);
FileInputStream fis = new FileInputStream(file.getAbsolutePath());
HWPFDocument document = new HWPFDocument(fis);
extractor = new WordExtractor(document);
String[] fileData = extractor.getParagraphText();
String Name="Not Found",Email="Not Found",Address="Not Found",Mob="Not Found";
for (int i = 0; i <fileData.length; i++)
{ int ind=0;
String temp=fileData[i].toLowerCase();
if(Name=="Not Found" && temp.contains("name")) {
ind=temp.indexOf("name");
temp=temp.substring(ind+4).replace(":"," ");
temp=temp.replace(" "," ");
Name=temp;
//System.out.println(temp);
}
if(Address=="Not Found" && temp.contains("address")) {
ind=temp.indexOf("address");
temp=temp.substring(ind+8).replace(":"," ");
temp=temp.replace(" "," ");
Address=temp;
//System.out.println(temp);
}
if(Email=="Not Found" && temp.contains("email")) {
ind=temp.indexOf("mailto");
temp=temp.substring(ind+6);
temp=temp.substring(0,temp.indexOf("\""));
temp=temp.replace(" "," ");
Email=temp;
//System.out.println(temp);
}
if(Mob=="Not Found" && (temp.contains("mob")||temp.contains("phone")||temp.contains("contact no"))) {
ind=temp.indexOf("phone");
temp=temp.substring(temp.indexOf(":"));
temp=temp.replace(" "," ");
Mob=temp;
//System.out.println(temp);
}
}
System.out.println("Name:"+Name+"\nEmail:"+Email+"\nMobile:"+Mob+"\nAddress:"+Address);
}
catch (Exception exep)
{
exep.printStackTrace();
}
}
}