title: SeekableByteChannel russian chars
body: <p>Recently I've started learning about <strong><em>java.nio</em></strong>. And I have an example in my textbook how to read text file with <strong><em>SeekableByteChannel</em></strong>:</p>
  
  <pre><code>int count;
  Path path;
  
  try {
      path = Paths.get(System.getProperty("user.home") + "/desktop/text.txt");
  } catch (InvalidPathException e) {
      out.println(e.getMessage());
      return;
  }
  
  try (SeekableByteChannel channel = Files.newByteChannel(path)) {
      ByteBuffer buffer = ByteBuffer.allocate(128);
  
      do {
          count = channel.read(buffer);
  
          if (count != -1) {
              buffer.rewind();
              for (int i = 0; i &lt; count; i++)
                  out.print((char) buffer.get());
          }
      } while (count != -1);
  
  } catch (IOException e) {
      out.println("File not found!!!");
  }
  
  out.flush();
  </code></pre>
  
  <p>So I've made a text file with english and russian words in it using an <strong>ANSI</strong> encoding. And this is what I get:</p>
  
  <p><a href="https://i.stack.imgur.com/NOAko.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NOAko.png" alt="output result"></a></p>
  
  <p>Method <em>buffer.get()</em> returns <em>byte</em> value and russian characters start from somewhere 1000. So I've changed encoding to <strong>UTF-8</strong> and used another method:</p>
  
  <pre><code>for (int i = 0; i &lt; count; i += 2)
      out.print(buffer.getChar()); //reads 2 bytes and converts them to char
  </code></pre>
  
  <p>But this gives me a line of question marks.</p>
  
  <p>So does anyone know how to properly read russian text using <strong><em>SeekableByteChannel</em></strong>?</p>