title: How can I read a file containing text and image data?
body: <p>I've got a file with the following structure:</p>
  
  <pre><code>&lt;number&gt;
  &lt;title&gt;
  &lt;text&gt;
  &lt;image data&gt;
  </code></pre>
  
  <p>For example:</p>
  
  <pre><code>176
  Elephant
  This image shows a cute elephant.
  &lt;image data bytes go here&gt;
  </code></pre>
  
  <p>I write the example above like this:</p>
  
  <pre><code>String filepath = "myfile.txt";
  BufferedImage image = ...; //load some image here
  
  try(FileOutputStream output = new FileOutputStream(filepath);
  BufferedWriter writer = new BufferedWriter(new FileWriter(filepath)))
  {
      writer.write("Number: 176");
      writer.newLine();
      writer.write("Title: Elephant");
      writer.newLine();
      writer.write("Text: This image shows a cute elephant.");
      writer.newLine();
  
      ImageIO.write(image, "png", output);
  
      writer.flush();
  }
  catch (Exception) {//exception handling}
  </code></pre>
  
  <p>This works fine. However, I do not know how to read the file.
  The problem is that I need to call ImageIO.read() to parse the image, but I can't call it with a BufferedReader. My draft looks like this:</p>
  
  <pre><code>String filepath = "myfile.txt";
  
  try (BufferedReader reader = new BufferedReader(new java.io.FileReader(filepath)))
  {
      String number = reader.readLine();
      reader.readLine(); //skip a free line
  
      String title = reader.readLine();
      reader.readLine(); //skip a free line
  
      String text = reader.readLine();
      reader.readLine(); //skip a free line
  
      BufferedImage image = ???; //how can I read the image here? &lt;----------------
  
  }
  catch (Exception e) {//error handling ...}
  </code></pre>
  
  <p><strong>So: How can I read the image (using ImageIO)?</strong></p>
  
  <p>Any help is very appreciated :)</p>
  
  <hr>
  
  <p><strong>EDIT: Like  I do the writing with two different Writers, is it possible to make use of two Readers while reading? Like "Read 3 lines of Strings, then read one line of binary data".</strong></p>