import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;

import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;

import org.apache.poi.hwpf.HWPFDocumentCore;
import org.apache.poi.hwpf.converter.WordToHtmlConverter;
import org.apache.poi.hwpf.converter.WordToHtmlUtils;
import org.w3c.dom.Document;


public class Main {

	public static void main(String[] args) {
		String docPath = "xxx.doc";
		convertDoc(docPath);
	}
	public static void convertDoc(String path) {
		try
		{
			// TODO Auto-generated method stub
			HWPFDocumentCore wordDocument = WordToHtmlUtils.loadDoc(new FileInputStream(path));

		    WordToHtmlConverter wordToHtmlConverter = new WordToHtmlConverter(
		            DocumentBuilderFactory.newInstance().newDocumentBuilder()
		                    .newDocument());
		    wordToHtmlConverter.processDocument(wordDocument);
		    Document htmlDocument = wordToHtmlConverter.getDocument();
		    ByteArrayOutputStream out = new ByteArrayOutputStream();
		    DOMSource domSource = new DOMSource(htmlDocument);
		    StreamResult streamResult = new StreamResult(out);

		    TransformerFactory tf = TransformerFactory.newInstance();
		    Transformer serializer = tf.newTransformer();
		    serializer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
		    serializer.setOutputProperty(OutputKeys.INDENT, "yes");
		    serializer.setOutputProperty(OutputKeys.METHOD, "html");
		    serializer.transform(domSource, streamResult);
		    out.close();

		    String result = new String(out.toByteArray());
		    System.out.println(result);
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
	}
}

@@ -46,26 +46,104 @@
 java.io.File
-In
+;%0Aimport java.io.FileInputStream;%0Aimport java.io.InputStream;%0Aimport java.io.Out
 putStream;%0A%0A
@@ -565,16 +565,242 @@
 lUtils;%0A
+import org.apache.poi.xwpf.converter.core.FileURIResolver;%0Aimport org.apache.poi.xwpf.converter.xhtml.XHTMLConverter;%0Aimport org.apache.poi.xwpf.converter.xhtml.XHTMLOptions;%0Aimport org.apache.poi.xwpf.usermodel.XWPFDocument;%0A
 import o
@@ -927,16 +927,22 @@
 nvertDoc
+ToHtml
 (docPath
@@ -944,16 +944,85 @@
 cPath);%0A
+%09%09%0A%09%09%0A%09%09String docxPath = %22xxx.docx%22;%0A%09%09convertDocxToHtml(docxPath);%0A
 %09%7D%0A%09publ
@@ -1031,20 +1031,22 @@
  static 
-void
+String
  convert
@@ -1052,16 +1052,22 @@
 tDoc
+ToHtml
 (String 
 path
@@ -1066,15 +1066,42 @@
 ing 
-path) %7B
+inputFile) %0A%09%7B%0A%09%09String html = %22%22;
 %0A%09%09t
@@ -1228,12 +1228,17 @@
 eam(
-path
+inputFile
 ));%0A
@@ -2112,21 +2112,12 @@
     
-String result
+html
  = n
@@ -2152,37 +2152,593 @@
 ;%0A%09%09
-    System.out.println(result
+%7D%0A%09%09catch(Exception e)%0A%09%09%7B%0A%09%09%09e.printStackTrace();%0A%09%09%7D%0A%09%09return html;%0A%09%7D%0A%09%0A%09static String convertDocxToHtml(String inputFile)%0A%09%7B%0A%09%09String html = %22%22;%0A%09%09try%0A%09%09%7B%0A%09%09//convert .docx to HTML string%0A%09        InputStream in= new FileInputStream(new File(inputFile));%0A%09        XWPFDocument document = new XWPFDocument(in);%0A%0A%09        XHTMLOptions options = XHTMLOptions.create().URIResolver(new FileURIResolver(new File(%22word/media%22)));%0A%0A%09        OutputStream out = new ByteArrayOutputStream();%0A%0A%0A%09        XHTMLConverter.getInstance().convert(document, out, options);%0A%09        html=out.toString(
 );%0A%09
@@ -2793,13 +2793,28 @@
 ();%0A%09%09%7D%0A
+%09%09return html;%0A
 %09%7D%0A%7D%0A

Update Main.java