破门点滴(Java技术版)

在日常学习和工作中记录

  BlogJava :: 首页 ::  :: 聚合  :: 管理
  15 Posts :: 7 Stories :: 36 Comments :: 0 Trackbacks

破门:看了下自己的这个技术blog,最近的一份帖子竟然是3月份的了。不由感慨,原来自己已经这么久没有涉及技术方面的工作内容了。
今天刚好安装 vTigerCRM 试用,从网上下载了5.0 b一个中文资源包,需要将资源包转换为UTF-8的编码。折腾一番后,发现利用Ant 1.6版本的Copy task 新增的一个特性可以轻松搞定批量的文件字符集编码转换,贴出来给大家共享。:)

build.xml 的详细内容

build.xml


稍微解释一下:


1、安装好ant环境。好像是废话,:)
2、按照你的资源文件命名修改 fileset, 比如改成 “**/*.properites”等等;
2、将修改后这个 build.xml 复制到你要进行批量文件编码转换的最上层目录;
3、在命令行进入上面的目录,敲入 ant  回车;
4、target 目录就是你所需要的东东了。

原理:
通过将当前文件复制到目标输出目录的copy 任务,设置 outputencoding 属性,可以轻松获得编码后的资源文件,:)
当然,你还可以设定ant 的filter token, 比如 “@ENCODING@”,来按照需要修改文件的内容。



不得窥道门,不得悟佛门,不得入窄门,实乃破门。
posted on 2006-09-01 16:33 破门 阅读(4742) 评论(9)  编辑  收藏 所属分类: Java

Feedback

# re: 通过Ant批量转换文件的字符集编码 2006-09-01 20:05 JonneyQuest
好东西,thank you  回复  更多评论
  

# re: 通过Ant批量转换文件的字符集编码 2006-09-01 21:46 wangpf
native2ascii taskdef 专门干这个的吧  回复  更多评论
  

# re: 通过Ant批量转换文件的字符集编码 2006-09-01 22:21 破门
@wangpf
native2ascii 是将指定的文件转换为 ASCII 编码。
比如 GB => ASCII等,如果需要 GB=> UTF-8 则不适用。  回复  更多评论
  

# re: 通过Ant批量转换文件的字符集编码 2006-09-01 23:28 三宝弟子
谢谢  回复  更多评论
  

# re: 通过Ant批量转换文件的字符集编码 2006-09-20 10:17 Adam
< target name ="init" >
< mkdir dir ="${target.dir}" />
</ target >

and

< target name ="clean" >
< delete dir ="${target.dir}" />
</ target >

this two modules maybe should be exchange their position, in my opinion, the dir should be cleaned first, then make a new dir for the output files.  回复  更多评论
  

# re: 通过Ant批量转换文件的字符集编码 2006-11-18 11:19 破门
@Adam
what you means can be done by change the line
< target name ="encoding" depends ="init" >

to
< target name ="encoding" depends ="clean, init" >
  回复  更多评论
  

# re: 通过Ant批量转换文件的字符集编码 2008-04-06 20:21 paaboo
您好,我在用这个copy方法的时候,复制一个本来就是utf-8文件却变成了乱码。。。
能不能帮我解释下?  回复  更多评论
  

# re: 通过Ant批量转换文件的字符集编码 2008-04-16 16:14 brokendoor
源文件已经是utf-8 再转换一次恐怕是会有问题的,因为这个copy命令使用了系统默认编码读取文件。  回复  更多评论
  

# re: 通过Ant批量转换文件的字符集编码 2008-05-26 13:05 paaboo
@brokendoor
哦 是否可以过滤已经是utf-8编码的文件?  回复  更多评论
  


只有注册用户登录后才能发表评论。


网站导航: