John Colson
John Colson

Reputation: 1

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 = 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?

Upvotes: 0

Views: 1612

Answers (3)

Gorky
Gorky

Reputation: 1413

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

Upvotes: 2

Daniel
Daniel

Reputation: 71

Java String is in UTF-16

Upvotes: 0

John
John

Reputation: 1

Yes, as I checked Clean and Build Main Project in Netbeans and then ran the jar file created in the dist folder.

Upvotes: 0

Related Questions