1

I am creating a string in my spring controller, it contain turkish characters

String str1 = "iş ortaklığı";

If i try to print it like System.setOut(new PrintStream(System.out,true,"UTF-8")); System.out.println(s);

output is iş ortaklığı

byte[] utf81 = str1.getBytes("UTF-8"); test3 = new String(utf8);

        System.out.println(test3);

output is iş ortaklığı

byte[] utf8 = str1.getBytes("windows-1254"); test3 = new String("windows-1254");

output is iþ ortaklýðý

But All the above code works fine in console program that is main method main method prints output like
iş ortaklığı

Any suggetion must appriciable

leppie
  • 115,091
  • 17
  • 196
  • 297
aat
  • 31
  • 3

1 Answers1

2

If you replace

System.setOut(new PrintStream(System.out,true,"UTF-8")); 

with

System.setOut(new PrintStream(new FileOutputStream(FileDescriptor.out),true,"UTF-8"));

then you'll get a System.out that UTF-8 encodes textual content to stdout instead of reencoding over the default encoding.

Java, default encoding explains Java's default encoding and how to manipulate that. If you have control over how your program is run, you might want to force the default encoding to UTF-8.

Community
  • 1
  • 1
Mike Samuel
  • 118,113
  • 30
  • 216
  • 245
  • still its not working for me in my spring controller output is iÅŸ ortaklığı – aat Dec 14 '12 at 05:15
  • @aat, have you looked at that output under hexdump to see if it is properly UTF-8 encoded or whether the reader that you're using is expecting a different encoding? – Mike Samuel Dec 14 '12 at 21:41
  • thanks for reply actually i am working in windows if i run my project in Linux its working still confusing with windows – aat Dec 17 '12 at 04:48
  • @aat, There is a [Windows version of `hexdump`](http://www.richpasco.org/utilities/hexdump.html). – Mike Samuel Dec 17 '12 at 14:09