title: PDF to Bytearray conversion in java
body: <p>Below is my code to convert a PDF file to byte array </p>
  
  <pre><code>public class ByteArrayExample{
  public static void main(String[] args) {
      try{
          BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
          System.out.println("Enter File name: ");
          String str = bf.readLine();
          File file = new File(str); 
          //File length
          int size = (int)file.length(); 
          if (size &gt; Integer.MAX_VALUE){
              System.out.println("File is to larger");
          }
          byte[] bytes = new byte[size]; 
          DataInputStream dis = new DataInputStream(new FileInputStream(file)); 
          int read = 0;
          int numRead = 0;
          while (read &lt; bytes.length &amp;&amp; (numRead=dis.read(bytes, read,
                  bytes.length-read)) &gt;= 0) {
              read = read + numRead;
          }
          System.out.println("File size: " + read);
          // Ensure all the bytes have been read in
          if (read &lt; bytes.length) {
              System.out.println("Could not completely read: "+file.getName());
          }
      }
    catch (Exception e){
    e.getMessage();
    }
    }
  }
  </code></pre>
  
  <p>Issue is this actually converts the file name into the byte array not the actual PDF file.Can anyone please help me with this.</p>