读取 Azure blob乱码

千百元 2015-12-21 12:13:29
public static void getBlobs() {
try {
CloudStorageAccount storageAccount = CloudStorageAccount.parse(storageConnectionString);
CloudBlobClient blobClient = storageAccount.createCloudBlobClient();
// CloudBlobContainer container = blobClient.getContainerReference("test");
CloudBlobContainer container = blobClient.getContainerReference("courtnew");

int i=0;
// 名字前缀
for (ListBlobItem blobItem : container.listBlobs("a", true)) {

i++;
System.out.println("----------------------------------------"+i);

CloudBlockBlob blob=(CloudBlockBlob) blobItem;
System.out.println("---------"+blob.downloadText());

String text=blob.downloadText();

if(!StringUtils.isNull(text)){
String s=StringUtils.getRightStringFromMessy(text);
System.out.println("-------------------- "+s);
}
}

} catch (Exception e) {
e.printStackTrace();
}
}


处理乱码方法
public static String[] ERCOEDING = { "й", "෨", "Ժ", "ۼ", "ҩ", "ල", "ɷ", "ص", "δ", "ġ", "Ϊ", "ط", "Ϣ", "ȡ", "Ӫ", "ã",
""};

public static String[] CHARSET = { "utf-8", "gbk", "gb2312", "gb18030", "big5" };



/**
* 将乱码转化为正常的字符
* @param str
* @param strEncode
* @return
* @throws UnsupportedEncodingException
* @return String
* @author liuming
* @date 2015年12月17日 下午3:41:37
*/
public static String getRightStringFromMessy(String str ) throws UnsupportedEncodingException{

String temp="";
if(StringUtils.isNull(str)){
return "";
}
int i=0;
for (String val : CHARSET) { // 匹配不同编码格式
temp=convertionString( str, val);
boolean garbled = getErrorCode(str);// 判断编码是否错误
if(garbled==true){
return temp;
}

if (garbled == false) {
i++;
if (i == 5) {
return "乱码";
}
continue;
}
}
return str;

}
...全文
247 1 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
千百元 2015-12-21
  • 打赏
  • 举报
回复
读取到的,有正常的,也有乱码, 明明有处理过乱码呀。汗。 写入时肯定没写乱码,因为写入前有做过处理

58,451

社区成员

发帖
与我相关
我的任务
社区描述
Java Eclipse
社区管理员
  • Eclipse
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧