Blob和Clob大数据类型-解决ClassLoader的getResource,getResourceAsStream 空格问题

Mysql常用的数据类型

tinyint/smallint/mediumint/int/bigint-->1B/2B/3B/4B/8B
float/double-->单精度/双精度浮点型
decimal-->不会产生精度丢失的单精度/双精度浮点型
date-->日期类型
time-->时间类型
datetime-->日期时间类型
year-->年类型
char-->定长字符串类型
varchar-->可变长字符串类型

tinyblob/blob/mediumblob/longblob-->255B/64K/16M/4G大小的图片/音乐等二进行数据

tinytext/text/mediumtext/longtext-->255B/64K/16M/4G大小的文本数据

解决ClassLoader的getResource,getResourceAsStream 中文和空格问题

ClassLoader的getResource方法使用了utf-8对路径信息进行了编码,当路径中存在中文和空格时,他会对这些字符进行转换,这样,得到的往往不是我们想要的真实路径,在此,调用了URLDecoder的decode方法进行解码,以便得到原始的中文及空格路径

例如:结果是file:/C:/Documents%20and%20Settings/%e5%ba%84%e6%99%93%e6%af%85/Local%20Settings/Temp/temp0.jar!/db/dmozdata.mdb  

 而我们期望是 C:/Documents andsettigsd sdfsdfsdf sdfsdf sdfsd 等等

 这里我们只要在获取到的例如: String configPath = this.getClass().getClassLoader().getResource("allowPath.xml").getFile();

把返回前decode下就可以了. 用utf-8编码. 

import java.net.URLDecoder;

URL uri = ClobDemo.class.getClassLoader().getResource("cn/zengfansheng/clob/java.txt");
File file = new File( URLDecoder.decode(uri.getPath(),"utf-8") );

  

posted @ 2013-04-04 01:09  hacket520  阅读(207)  评论(0)    收藏  举报