title: DataInputStream vs InputStreamReader, trying to conceptually understand the two
body: <p>As I tentatively understand it at the moment:</p>
  
  <p><code>DataInputStream</code> is an <code>InputStream</code> subclass, hence it reads and writes bytes. If you are reading bytes and you know they are all going to be <code>int</code>s or some other primitive data type, then you can read those <code>byte</code>s directly into the primitive using <code>DataInputStream</code>. </p>
  
  <ul>
  <li>Question: <em>Would you would need to know the type (int, string, etc) of the content being read before it is read? And would the whole file need to consist of that one primitive type?</em></li>
  </ul>
  
  <p><strong>The question I am having is</strong>: Why not use an <code>InputStreamReader</code> wrapped around the <code>InputStream</code>'s byte data? With this approach you are still reading the bytes, then converting them to integers that represent characters. Which integers represent which characters depends on the character set specified, e.g., "UTF-8".</p>
  
  <ul>
  <li>Question: <em>In what case would an <code>InputStreamReader</code> fail to work where a <code>DataInputStream</code> would work?</em></li>
  </ul>
  
  <p><strong>My guess answer</strong>: If speed is really important, and you can do it, then converting the <code>InputStream</code>'s byte data directly to the primitive via <code>DataInputStream</code> would be the way to go? This avoids the <code>Reader</code> having to "cast" the byte data to an <code>int</code> first; and it wouldn't rely on providing a character set to interpret which character is being represented by the returned integer. I suppose this is   what people mean by <code>DataInputStream</code> allows for a machine-indepent read of the underlying data.</p>
  
  <ul>
  <li>Simplification: <code>DataInputStream</code> can convert bytes directly to primitives.</li>
  </ul>
  
  <p><strong>Question that spurred the whole thing</strong>: I was reading the following tutorial code:</p>
  
  <pre><code>    FileInputStream fis = openFileInput("myFileText");
  
      BufferedReader reader = new BufferedReader( new InputStreamReader( new DataInputStream(fis)));
  
      EditText editText = (EditText)findViewById(R.id.edit_text);
  
      String line;
  
      while(  (line = reader.readline()) != null){
  
          editText.append(line);
          editText.append("\n");
      }
  </code></pre>
  
  <p>...I do not understand why the instructor chose to use <code>new DataInputStream(fis)</code> because it doesn't look like any of the ability to directly convert from bytes to primitives is being leveraged? </p>
  
  <ul>
  <li><strong>Am I missing something?</strong></li>
  </ul>
  
  <p>Thanks for your insights.</p>