日期:2014-05-20  浏览次数:20722 次

有关通讯录导入编码问题n73
FileConnection   fc=null;
InputStream   is   =   null;
byte[]   data;
fc   =   (FileConnection)   Connector.open( "某文件正确 ",Connector.READ_WRITE);
if(fc.exists()){
is=fc.openInputStream();
StringBuffer   sb=   new   StringBuffer();
int   ch;
ContactList   contactList   =   (ContactList)PIM.getInstance().openPIMList(PIM.CONTACT_LIST,   PIM.READ_WRITE);
while((ch=is.read())!=-1){
sb.append((char)ch);
if(sb.toString().endsWith( "END:VCARD\r\n ")){
data=new   byte[sb.length()];
for(int   j=0;j <sb.length();j++){
data[j]=(byte)sb.charAt(j);
} ByteArrayInputStream   bais=new   ByteArrayInputStream(data);
//.......真机错误,模拟器OK。
PIMItem[]   pi   =   PIM.getInstance().fromSerialFormat(bais, "utf-8 ");
Contact   contact2   =   contactList.importContact((Contact)pi[0]);
contact2.commit();
sb.delete(0,sb.length());
}
}
}


代码就是上面那样了,为什么在那一句会出错呢?java.io.UnsupportedEncodingException
在模拟器里没有问题,在N73里出现问题。导出通讯录的时候,是可以导出的,也可以打开导出的文件。

------解决方案--------------------
你先用supportedSerialFormats()方法看看手机支持的编码格式再说