title: Can't read from binary file - read some lines in UTF-8, some in binary
body: <p>I have this code:</p>
  <pre><code>import java.io.*;
  import java.nio.charset.StandardCharsets;
  
  public class Main  {
      public static void main(String[] args) {
          zero(&quot;zero.out&quot;);
          System.out.println(zeroRead(&quot;zero.out&quot;));
      }
  
      public static String zeroRead(String name)  {
  
          try (FileInputStream fos = new FileInputStream(name);
               BufferedInputStream bos = new BufferedInputStream(fos);
               DataInputStream dos = new DataInputStream(bos)) {
  
              StringBuffer inputLine = new StringBuffer();
              String tmp;
              String s = &quot;&quot;;
              while ((tmp = dos.readLine()) != null) {
                  inputLine.append(tmp);
                  System.out.println(tmp);
              }
              dos.close();
              return s;
          }
          catch (IOException e)  {
              e.printStackTrace();
          }
  
          return null;
      }
  
  
      public static void zero(String name)  {
          File file = new File(name);
          String text = &quot;König&quot; + &quot;\t&quot;;
  
          try (FileOutputStream fos = new FileOutputStream(file);
               BufferedOutputStream bos = new BufferedOutputStream(fos);
               DataOutputStream dos = new DataOutputStream(bos)) {
  
               dos.write(text.getBytes(StandardCharsets.UTF_8));
               dos.writeInt(50);
          } catch (IOException e) {
              e.printStackTrace();
          }
      }
  }
  </code></pre>
  <p><code>zero()</code> method writes data into file: the string is written in UTF-8, while the number is written in binary. <code>zeroRead()</code> read the data from file.</p>
  <p>The file looks like this after zero() is executed:</p>
  <p><a href="https://i.stack.imgur.com/sHpIt.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/sHpIt.png" alt="enter image description here" /></a></p>
  <p>This is what <code>zeroRead()</code> returns:</p>
  <p><a href="https://i.stack.imgur.com/95Reo.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/95Reo.png" alt="enter image description here" /></a></p>
  <p>How do I read the real data <code>König\t50</code> from the file?</p>