title: reading unicode characters from properties file java
body: <p>Please help me to read the UNICODE characters as it is from the properties file in java. For example : if I pass the key "Account.label.register" it should return to me as "\u5BC4\u5B58\u5668" but not its character representation like "寄存器" .  Here is my sample properties file</p>
  
  <p>file_ch.properties</p>
  
  <pre><code>Account.label.register = \u5BC4\u5B58\u5668 
  Account.label.login = \u767B\u5F55 
  Account.label.username = \u7528\u6237\u540D 
  Account.label.password = \u5BC6\u7801 
  </code></pre>
  
  <p>Thank you.</p>
  
  <p>Hi ,  I am reading properties file using the following java code</p>
  
  <pre><code>@Override
  public ResourceBundle getTexts(String bundleName) {
      ResourceBundle myResources = null;
      try {
          myResources = ResourceBundle.getBundle(bundleName, getLocale());
      } catch (Exception e) {
          myResources = ResourceBundle.getBundle(getDefaultBundleKey(), getLocale());
      }
      return myResources;
  }
  </code></pre>
  
  <p>Using the above approach it's ok fine, I am getting chinese characters.  But for some of the ajax requests in my application I need to pass the chinese text in X-JSON header.  Sample code is given below</p>
  
  <pre><code>    HashMap&lt;String, List&lt;String&gt;&gt; map = new HashMap&lt;String, List&lt;String&gt;&gt;();
      List&lt;String&gt; errors = new ArrayList&lt;String&gt;();
      errors.add(str);   /*ex: str = "无效的代码" , value taken from properties file through resource bundle*/
      map.put("ERROR", errors);
      JSONObject json = JSONObject.fromObject(map);
      response.setCharacterEncoding("UTF-8");
      response.setHeader("X-JSON", json.toString());
      response.setStatus(500);
  </code></pre>
  
  <p>I am passing english for example str="Invalid Code"  X-JSON header is carrying the information as it is.  But if the str="无效的代码" (chinese or any other text) X-JSON header is carrying the text as empty like below is the response I am getting</p>
  
  <pre><code> response :
  
   connection:close
   Content-Encoding:gzip
   Content-Type:text/html;charset=UTF-8
   Date:Wed, 08 Jun 2016 10:17:43 GMT
   Server:Apache-Coyote/1.1
   Transfer-Encoding:chunked
   Vary:Accept-Encoding
   X-JSON:{"ERROR":["Invalid Code"]}
  </code></pre>
  
  <p>However if the "error" contains "chinese" text for ex:"无效的代码"</p>
  
  <p>response :</p>
  
  <pre><code> connection:close
   Content-Encoding:gzip
   Content-Type:text/html;charset=UTF-8
   Date:Wed, 08 Jun 2016 10:17:43 GMT
   Server:Apache-Coyote/1.1
   Transfer-Encoding:chunked
   Vary:Accept-Encoding
   **X-JSON:{"ERROR":["  "]}**   /*expecting the response X-JSON:{"ERROR":["无效的代码"]}*/
  </code></pre>
  
  <p>As the chinese text is coming as empty , I thought of sending unicode through X-JSON header like below</p>
  
  <pre><code>{"ERROR":["\u65E0\u6548\u7684\u4EE3\u7801"]}  
  </code></pre>
  
  <p>After that want to parse the Unicode characters using Javascript code after evaluating X-JSON header like below</p>
  
  <pre><code>var json;
    try {
      json = xhr.getResponseHeader('X-Json');
    } catch (e) {
      alert(e);
   }
  
    if (json) {
      var data = eval('(' + json + ')'); 
      decodeMsg(data);
    }
  
  
    function decodeMsg(message) {
      var mssg =  message;
      var r = /\\u([\d\w]{4})/gi;
      mssg = mssg.replace(r, function (match, grp) {
          return String.fromCharCode(parseInt(grp, 16)); } );
      mssg = unescape(mssg);
  
      return mssg;
   }
  </code></pre>
  
  <p>Please give suggestions.  Thank you.</p>