title: Reading several byte[] from DataInputStream
body: <p>What I need to do is send multiple files using DataStreams. I'm doing this by sending the name of the file, and then the file's bytes. I need to send an undetermined number of files though. Here is the <code>DataOutputStream</code> code.</p>
  
  <pre><code>            out.writeUTF(path);
              out.write(Files.readAllBytes(file.toPath()));
  </code></pre>
  
  <p>It does that for each file that needs to be sent. But I don't know how to read it correctly with <code>DataInputStream</code>. This is what I have so far.</p>
  
  <pre><code>    while (in.available() != 0) {
          String path = in.readUTF();
          byte bytes = in.readByte();
      }
  </code></pre>
  
  <p>Obviously it wouldn't work, since it is only reading one byte. But I don't know how to make it read all of the bytes. Since there are several files being sent, <code>available()</code> would only equal 0 when the end of all the files are read, I think. Any help is greatly appreciated.</p>
  
  <p>Something I completely forgot to mention, I want to be able to send a large file without running out of memory, and I don't think this would work. I think I would need to use a buffer, but I don't know what class supports that with files.</p>