zoukankan      html  css  js  c++  java
  • java处理中日文字符串的乱码问题

    ——杂言:前段时间在处理音频预览问题,详见关于audiojs的研究。期间,将远端的音频下载并缓存在本地过程中,涉及到java.io.*的几个操作,发生一些乱码问题。

    我以前的处理是将本地的编码转换为UTF-8,但是这次不灵额。网上查了些博客,有说是专成ISO8859-1,的确是ok了的。

     1 public static String previewAudio(long fileId, String fileUrl, String fileName) {
     2     fileName = fileName.replaceAll(" ", "");
     3     String encoding = System.getProperty("file.encoding");// 此处是获取原有的编码方式
     4     String pathName = "";
     5     try {
     6         pathName = "/tmp/audio/" + fileId + "_"
     7         + new String(fileName.getBytes(encoding), "ISO8859-1");// 将pathName的编码转成ISO8859-1
     8         File file = new File(basePath + pathName);
     9         if (!file.exists()) {
    10             FileUtils.copyURLToFile(new URL(fileUrl), file);// 用的org.apache.commons.io.FileUtil
    11         }
    12     } catch (UnsupportedEncodingException e1) {
    13         e1.printStackTrace();
    14     } catch (MalformedURLException e) {
    15         e.printStackTrace();
    16     } catch (IOException e) {
    17         e.printStackTrace();
    18     }
    19     return pathName;
    20 }
  • 相关阅读:
    #include <boost/scoped_ptr.hpp>
    #include <boost/function.hpp>
    #include <boost/bind.hpp>
    8.4散列表查找
    #include <boost/array.hpp>
    异常
    lambda
    #include <amp.h>
    #include <bitset>
    #include <hash_set>
  • 原文地址:https://www.cnblogs.com/timelyxyz/p/3488308.html
Copyright © 2011-2022 走看看