title: Java how to read part of file from specified position of bytes?
body: <p>I have a situation when I need to read only part of file, beginning from specified byte position.</p>
  
  <p>I try with next :</p>
  
  <pre><code>protected void writePartToStream(final InputStream in, final OutputStream out, long startBytes) {
          final byte[] b = new byte[BUFFER_SIZE];
          int count = 0;
          amountWritten = startBytes;
  
  
          // skip logic
          // how to skip???
  
          do {
              // write to the output stream
              try {
  
  
                  out.write(b, 0, count);
                  out.flush();
              } catch (IOException e) {
                  e.printStackTrace();
              }
  
              amountWritten += count;
              System.out.println("Amount writtent=" + amountWritten);
              // read more bytes from the input stream
              try {
                  count = in.read(b, (int) amountWritten, b.length);
              } catch (IOException e) {
              }
          } while (count != -1 &amp;&amp; !getStatus().equals(Status.cancelled));
  
          // the connection was likely terminated abrubtly if these are not equal
          if (!getStatus().equals(Status.cancelled) &amp;&amp; getError() == Error.none
                  &amp;&amp; amountWritten != fileSize) {
              setStatus(Status.error);
              this.error = Error.connection;
          }
      }
  </code></pre>
  
  <p>But I never working with I/O, so I don't have any idea how to start read file, from specified position.</p>