正在阅读:用Java将文件名从中文转为拼音用Java将文件名从中文转为拼音

2004-12-09 10:11 出处:PConline 作者:guoxiaoshou2000 责任编辑:linjixiong

  

  //要转换的word文件
  String inFile = docpath;
  //txt文件
  String tpFile = txtpath;

  boolean flag = false;
  
  try
  {
  //设置word不可见
  app.setProperty("Visible", new Variant(false));
  Object docs = app.getProperty("Documents").toDispatch();
  //打开word文件
  Object doc = Dispatch.invoke(docs,"Open",
  Dispatch.Method, new Object[]{inFile,
  new Variant(false), new Variant(true)},
  new int[1]).toDispatch();
  //作为txt格式保存到临时文件
  Dispatch.invoke(doc,"SaveAs", Dispatch.Method,
  new Object[]{tpFile,new Variant(10)},
  new int[1]);
  Variant f = new Variant(false);
  Dispatch.call(doc, "Close", f);
  flag = true;
  }
  catch (Exception e)
  {
  e.printStackTrace();
  }
  finally
  {
  app.invoke("Quit", new Variant[] {});
  }
  System.out.println("转化完毕!\n--------");
  }
  }
  else
  {
  pathss = paths;
  //进入下一级目录
  pathss = pathss + lists[i].getName() + "\\";   
  //递归遍历所有目录
  change(path, pathss, savepaths);
  }
  }
  
  }
  
  public static String formatname(String name)
  {
  name = name.replace('、', '_');
  name = name.replace(')', ')');
  name = name.replace('(', '(');
  return name;
  }
  
  public static String pinyin(String path, String hanzi)
  {
  File f = new File(path);
  String pinyin = new String("");
  pinyin = hanzi;

察看评论详细内容 我要发表评论
作者笔名 简短内容 发表时间
:

键盘也能翻页,试试“← →”键

关注我们

最新资讯离线随时看 聊天吐槽赢奖品