title: character encoding in java
body: <p>I have tried the code below:</p>
  
  <pre><code>public static void main(String[] args) throws IOException {
      String s = "NETWORK";
      try (
              FileOutputStream fos = new FileOutputStream("d:/endian.txt");
              OutputStreamWriter osw = new OutputStreamWriter(fos, "UTF_16BE");) {
          osw.write(s);
          osw.flush();
  
      }
  }
  </code></pre>
  
  <p>after running, I get a file that contains the following chain: N E T W O R K; the size of the resulting file is 14 bytes (7 characters * 2 bytes). notice the spaces between characters of the chain.
  when I change the encoding with: UTF_16LE, I get a file size of 14 bytes, which contains the following string: NETWORK. no spaces between characters !!. I expect a string as follows: N E T W O R K. i used notepad to open the file.
  Can anyone explain this behavior?</p>