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

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

  将指定目录下面得所有文件名从中文转化为拼音,并保存为html,其中拼音和汉字对照得文件可以通过Windows自带得程序获得。又是一个小程序。



  public class hanzipinyin
  {
  public static void change(String path, String paths, String savepaths)
  {
  
  File d = new File(paths);
  //取得当前文件夹下所有文件和目录的列表
  File lists[] = d.listFiles();
  String pathss = new String("");

  //对当前目录下面所有文件进行检索
  for(int i = 0; i < lists.length; i ++)
  {
  if(lists[i].isFile())
  {
  //得到doc文件名
  String filename = lists[i].getName();
  //定义最简文件名
  String realfilename = new String(filename.substring(0,
  (filename.length() - 4)));
  
  //定义文件全名为路径加文件名
  String fullsavefilename = paths + realfilename;
  fullsavefilename = fullsavefilename.replace('\\', '_');
  fullsavefilename = fullsavefilename.replace(':', '@');
  fullsavefilename = fullsavefilename.substring(
  47, fullsavefilename.length());

  //定义文件类型
  String filetype = new String("");

  filetype = filename.substring((filename.length() - 3),
  filename.length());
  
  if(filetype.equals("doc"))
  {
  System.out.println("--------\n当前正在转换......");
  //打印当前目录路径
  System.out.println(paths);
  //打印doc文件名
  System.out.println(realfilename);
  
  //启动word
  ActiveXComponent app =
  new ActiveXComponent("Word.Application");
  
  String docpath = paths + filename;
  String txtpath = savepaths + fullsavefilename + ".htm";
  
  //格式化文件名
  txtpath = formatname(txtpath);    
  //将中文文件名改为拼音
  txtpath = pinyin(path, txtpath);

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

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

关注我们

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