前面shuyanxu朋友提到javadbf(
http://fireshort.blogbus.com/logs/2005/09/1420670.html
)的中文支持问题,由于我测试得不够仔细就忽略掉了。最近发现读取中文是没有问题的,但写入dbf的时候就会产生乱码。
设了几个断点之后跟踪发现是Utils中的textPadding方法有错,原来的方法是
public static byte[] textPadding( String text, String characterSetName, int length, int alignment,
byte paddingByte) throws java.io.UnsupportedEncodingException {
if( text.length() >= length) {
return text.substring( 0, length).getBytes( characterSetName);
}
byte byte_array[] = new byte[ length];
Arrays.fill( byte_array, paddingByte);
switch( alignment) {
case ALIGN_LEFT:
System.arraycopy( text.getBytes( characterSetName), 0, byte_array, 0, text.length());
break;
case ALIGN_RIGHT:
int t_offset = length - text.length();
System.arraycopy( text.getBytes( characterSetName), 0, byte_array, t_offset, text.length());
break;
}
return byte_array;
}
我改为了
public static byte[] textPadding(String text,String characterSetName,
int length,int alignment,byte paddingByte)
throws java.io.UnsupportedEncodingException
{
byte[] srcByteArray=text.getBytes(characterSetName);
byte[] dstByteArray=new byte[length];
Arrays.fill(dstByteArray,paddingByte);
int dstLength=0;
if(srcByteArray.length>=length)
{
dstLength=length%2==0?length:length-1;
}else
{
dstLength=srcByteArray.length;
}
switch(alignment)
{
case ALIGN_LEFT: System.arraycopy(srcByteArray,0,dstByteArray,0,dstLength);
break;
case ALIGN_RIGHT:
System.arraycopy(srcByteArray,0,dstByteArray,length-dstLength,dstLength);
break;
}
return dstByteArray;
}
中文输出完全正常了。
附件是打过补丁后的javadbf.jar。
分享到:
相关推荐
javadbf解决中文截取
使用Javadbf时解决DBF中文写入乱码问题,用此javadbf-0.4.0.jar代替官方原jar文件即可解决
javadbf, 解决dbf中 ,中文乱码的问题。。。。。。。。。。。。。
基于javadbf-0.4.0而修改的,导入dbf文件时标题转码采用系统默认编码处改为采用用户自定义的转码格式,从而解决标题乱码的问题
用于在java代码中写入dbf文件并输出文件。在原代码的使用过程中,对于姓名字段中不常见的汉字,会变成“?”号,比如“张芃”,会变成“张?”,这个包是修复这个问题的。
通过修改默认字符集及写入dbf时所用的方法,使原有的javadbf增加了中文内容及中文字段名的支持;奉上写入dbf文件中文内容及中文标题的代码示例
DBF的ODBC建立方法: X86server,进入 控制面板--系统和安全--管理工具--ODBC数据源--右键管理员方式运行 X64(win7,server):C:\windows\sysWow64\odbcad32.exe 右键管理员方式运行,如图1 在"系统DSN"中找到刚...
基于javadbf-0.4.0修改而来,a.修改了基类中的默认字符编码;b.修改了写入类中的字节填充位置计算方法,使之支持双字节; 补充:通常dbf使用excel打开时,gb2312的中文能正常显示,utf8的不行,所以默认字符集设置成...
javadbf-0.4.0版本本已增加setCharactersetName方法支持中文读写,但在写入时会发生写入中文数据丢失问题。资源压缩文件包含有修改后的jar文件和读写测试类。 @Test public void testWrite1(){ File file=new File...
此前下载了官方的javadbf-0[1].4.0.jar使用过程中出现中文乱码.经过本人修改后已经解决次问题
使用Javadbf时解决DBF中文写入乱码问题,用此javadbf-0.4.0.jar代替官方原jar文件即可解决; 使用Javadbf时解决DBF中文写入乱码问题,用此javadbf-0.4.0.jar代替官方原jar文件即可解决;
请审核人员注意,这不是重复上传,上一个版本存在bug,有人联系我之后再次修订上传,解决保存中文数据会丢失部分的问题, 默认编码UTF-8,如果有使用其它编码的,可以调用writer的设置编码的方法 writer....
java输出dbf所需包,最新版,解决内容中包含中文导致结果只有一半字符的问题,输出dbf文件主要是为了设置打开shp文件的时候对应字段的长度和精度设置
读取dbf文件,解决中文读取报错的问题
DBF:dBASE文件,一种由Ashton-Tate创建的格式,可以被ACT!、Lipper、FoxPro、Arago、Wordtech、Xbase和类似数据库或与数据库有关产品识别;可用数据文件(能被Excel 97打开);Oracle 8.1.x表格空间文件 DBX:...