JAVA 中查找亂碼字符

最近項目中遇到一個問題,客戶電腦中的自造字在JAVA中認不出來,導致上傳的文件亂碼顯示。
此方法雖然不能正確顯示出自造字,可是可以查找到亂碼的部分。(哪位大神如果知道JAVA中顯示系統自造字請告知呵!)
 
FileInputStream fis = new FileInputStream(filePath);
  int b = fis.read();
  List res = new ArrayList();
  ByteOutputStream bos = new ByteOutputStream();
  while (b != -1) {
   if (b != '\r' && b != '\n') {
    bos.write(b);
   }
   if (b == '\n') { // suppose there always are "\r\n"
    res.add(Arrays.copyOf(bos.getBytes(), bos.getCount()));
    bos.close();
    bos = new ByteOutputStream();
   }
   b = fis.read();
  }
  if (bos.getBytes().length > 0) {
   res.add(Arrays.copyOf(bos.getBytes(), bos.getCount()));
   bos.close();
  }
  fis.close();
 
 
 
File f = new File(fileName);
  if (!f.exists()) {
   File dir = new File(f.getParent());
   if (!dir.exists()) {
    dir.mkdirs();
   }
  }
  FileOutputStream fos = new FileOutputStream(f,true);
  byte[] bytes = new String(content, "big5").getBytes("big5");
   if (bytes.length != content.length) {
    for (int j = 0, k = 0; j < content.length; j++) {
     if (content[j] != bytes[k++]) {
      content[j++] = 63;
      if(j       content[j] = 63;
      }
     }
    }
   }
  fos.write(content);
  if(islast=="N"){
   fos.write('\r');
   fos.write('\n');
  }
  fos.close();

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/27147629/viewspace-736069/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/27147629/viewspace-736069/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值