1. public class Test3 {  
  2.  
  3.     /**  
  4.      *   
  5.      * @param path  
  6.      * @param paths  
  7.      * @param savepaths  
  8.      */ 
  9.     public static void change(String path, String paths, String savepaths) {  
  10.         File d = new File(paths);  
  11.         // 取得当前文件夹下所有文件和目录的列表  
  12.         File lists[] = d.listFiles();  
  13.         String pathss = new String("");  
  14.         // 对当前目录下面所有文件进行检索  
  15.         for (int i = 0; i < lists.length; i++) {  
  16.             if (lists[i].isFile()) {  
  17.                 // 得到doc文件名  
  18.                 String filename = lists[i].getName();  
  19.                 // 定义最简文件名  
  20.                 String realfilename = new String(filename.substring(0,  
  21.                         (filename.length() - 4)));  
  22.  
  23.                 // 定义文件全名为路径加文件名  
  24.                 String fullsavefilename = paths + realfilename;  
  25.                 fullsavefilename = fullsavefilename.replace('/''_');// /////  
  26.                 fullsavefilename = fullsavefilename.replace(':''@');  
  27.                 // fullsavefilename = fullsavefilename.substring(47,  
  28.                 // fullsavefilename.length());  
  29.  
  30.                 // 定义文件类型  
  31.                 String filetype = new String("");  
  32.  
  33.                 filetype = filename.substring((filename.length() - 3),  
  34.                         filename.length());  
  35.  
  36.                 if (filetype.equals("doc")) {  
  37.                     System.out.println("--------/n当前正在转换......");  
  38.                     // 打印当前目录路径  
  39.                     System.out.println(paths);  
  40.                     // 打印doc文件名  
  41.                     System.out.println(realfilename);  
  42.  
  43.                     // 启动word  
  44.                     ActiveXComponent app = new ActiveXComponent(  
  45.                             "Word.Application");  
  46.  
  47.                     String docpath = paths + filename;  
  48.                     String txtpath = savepaths + fullsavefilename + ".htm";  
  49.  
  50.                     // 格式化文件名  
  51.                     txtpath = formatname(txtpath);  
  52.                     // 将中文文件名改为拼音  
  53.                     txtpath = pinyin(path, txtpath);  
  54.  
  55.                     // 要转换的word文件  
  56.                     String inFile = docpath;  
  57.                     // txt文件  
  58.                     String tpFile = txtpath;  
  59.                     boolean flag = false;  
  60.  
  61.                     try {  
  62.                         // 设置word不可见  
  63.                         app.setProperty("Visible"new Variant(false));  
  64.                         Object docs = app.getProperty("Documents").toDispatch();  
  65.                         // 打开word文件  
  66.                         Object doc = Dispatch.invoke(  
  67.                                 (Dispatch) docs,  
  68.                                 "Open",  
  69.                                 Dispatch.Method,  
  70.                                 new Object[] { inFile, new Variant(false),  
  71.                                         new Variant(true) }, new int[1])  
  72.                                 .toDispatch();  
  73.                         // 作为txt格式保存到临时文件  
  74.                         Dispatch.invoke((Dispatch) doc, "SaveAs",  
  75.                                 Dispatch.Method, new Object[] { tpFile,  
  76.                                         new Variant(10) }, new int[1]);  
  77.                         Variant f = new Variant(false);  
  78.                         Dispatch.call((Dispatch) doc, "Close", f);  
  79.                         flag = true;  
  80.                     } catch (Exception e) {  
  81.                         e.printStackTrace();  
  82.                     } finally {  
  83.                         app.invoke("Quit"new Variant[] {});  
  84.                     }  
  85.                     System.out.println("转化完毕!/n--------");  
  86.                 }  
  87.             } else {  
  88.                 pathss = paths;  
  89.                 // 进入下一级目录  
  90.                 pathss = pathss + lists[i].getName() + "//";  
  91.                 // 递归遍历所有目录  
  92.                 change(path, pathss, savepaths);  
  93.             }  
  94.         }  
  95.  
  96.     }  
  97.  
  98.     public static String formatname(String name) {  
  99.         name = name.replace('、''_');  
  100.         name = name.replace(')'')');  
  101.         name = name.replace('(''(');  
  102.         return name;  
  103.     }  
  104.  
  105.     public static String pinyin(String path, String hanzi) {  
  106.         File f = new File(path);  
  107.         String pinyin = new String("");  
  108.         pinyin = hanzi;  
  109.         try {  
  110.             FileReader fr = new FileReader(f);  
  111.             BufferedReader br = new BufferedReader(fr);  
  112.             String line = new String("");  
  113.             line = br.readLine();  
  114.             int count = 0;  
  115.             int location = 0;  
  116.             while (line != null) {  
  117.                 while (pinyin.indexOf(line.charAt(0)) != -1) {  
  118.                     location = pinyin.indexOf(line.charAt(0));  
  119.                     pinyin = pinyin.substring(0, location)  
  120.                             + line.substring(12)  
  121.                             + pinyin.substring(location + 1, pinyin.length());  
  122.                 }  
  123.                 line = br.readLine();  
  124.                 System.out.print("/b/b/b/b/b/b" + count++);  
  125.             }  
  126.             fr.close();  
  127.             br.close();  
  128.         } catch (Exception e) {  
  129.             // System.err.println(e);  
  130.         }  
  131.         return pinyin;  
  132.     }  
  133.  
  134.     public static void main(String[] args) {  
  135.  
  136.         String paths = new String("e://360Downloads//");  
  137.         String savepaths = new String("e://360Downloads//Video//");  
  138.         String path = new String("e://360Downloads//pinyin.doc");  
  139.  
  140.         change(path, paths, savepaths);  
  141.     }  

 

 

 

下载jacob.rar,解压出jacob.dll和jacob.jar

 
然后:
1) 把jacob.dll在 C:\Program Files\Java\jdk1.5.0_08\bin、C:\Program Files\Java\jdk1.5.0_08\jre\bin、C:\WINDOWS\system32    目录下各.放一份
2) 把jacob.jar放入 项目的lib包下,并且在“java构建路径”中也要加载此jar包。.
3) 运行项目即可编译通过.

 


注:
    1)这样配置后不需要再配置环境变量(如:path,classpath)了.
详见附件