Problem with utf8 encoding Java strings using Netbeans
I have written a program that sends a request to the Yahoo API in several natural languages. The encoding on Yahoo has to be utf8. No problem in Delphi or Perl. In my Java version, I convert the search query sQuery1 like this: try{ utf8Bytes 开发者_StackOverflow中文版= sQuery1.getBytes("utf-8"); sQuery8 = new String(utf8Bytes, "utf-8"); } catch (etc.) Works fine when compiled from the command line. But when I type exactly the same code with Netbeans and run the jar, the Yahoo server sends an error message each time I use special characters like French accents (works fine for English though). Apparently, the jar compiled with Netbeans doesn't take the utf8 conversion into account. When run from Netbeans itself, the program works fine. Any explanation?
I have a batch file to call my jar. As soon as I have changed it like below, everything worked like a charm:
java -Dfile.encoding=utf-8 -jar MultiLangugePain.jar
Yes, as I checked Clean and Build Main Project in Netbeans and then ran the jar file created in the dist folder.
Java String is in UTF-16
精彩评论