title: Taking Japanese or Chinese input from System.in Java
body: <p>I am trying to take in Japanese characters for a little echo server I wrote.  The problem is that when I get the characters from System.in (via anything, scanner, <code>InputStream</code>, you name it) They always come in as garbage.  I even tried using the </p>
  
  <pre><code>message = new String(bufferedReader.readLine().getBytes("UTF8");  
  </code></pre>
  
  <p>in order to try to get the bytes to come in as Unicode.</p>
  
  <p>When I print a message from the server ようこそ (welcome in japanese) it comes up fine, the problem only exists when taking user input.</p>
  
  <p>The console is set up to use UTF8 in eclipse.</p>
  
  <p>Here is a small test program I wrote to make sure it was the input from System.in</p>
  
  <p>the input and output are</p>
  
  <pre><code>よ
  ã‚ˆ
  </code></pre>
  
  <p>And here is the code</p>
  
  <pre><code>public class TestUnicode {
  
  public static void main(String[] args) throws IOException
  {
      BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in, "UTF8"));
      String message = stdIn.readLine();
      System.out.println(message);
  }
  </code></pre>
  
  <p>}</p>
  
  <pre><code>public class Client {
  
  public static void main(String[] args) throws IOException 
  {
      Socket serverSocket = null;
  
      try
      {
          serverSocket = new Socket("192.168.1.127", 3000); //connect to myself at port 3000
      }
      catch(IOException e)
      {
          System.out.println(e);
          System.exit(1);
      }
  
      BufferedReader in = null;
      PrintStream out = null;     
      try //create in and out to write and read from echo
      {
          in = new BufferedReader(new InputStreamReader(serverSocket.getInputStream()));
          out = new PrintStream(serverSocket.getOutputStream(), true);
      }
      catch(IOException e)
      {
          serverSocket.close();
          System.out.println(e);
          System.exit(1);
      }
  
      String message = null;
      message = in.readLine();
      System.out.println(message); //print out the welcome message
  
      BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
      //create a new buffered reader from my input
  
      try
      {
          while(true)
          {
              message = bufferedReader.readLine();
              out.println(message); //send a line to the server
              if(message.equals("quit"))
              {
                  System.out.println(in.readLine());
                  break;
              }
              System.out.println(in.readLine()); //get it back and print it               
          }
  
          System.out.println("Quiting client...");
      }
      catch(IOException e)
      {
          in.close();
          out.close();
          serverSocket.close();
          System.out.println(e);
          System.exit(1);
      }
  
      in.close();
      out.close();
      serverSocket.close();
  }
  }
  </code></pre>