Android download PDF from URL then open it with a PDF reader

Hi the problem is in FileDownloader class urlConnection.setRequestMethod(“GET”); urlConnection.setDoOutput(true); You need to remove the above two lines and everything will work fine. Please mark the question as answered if it is working as expected. Latest solution for the same problem is updated Android PDF Write / Read using Android 9 (API level 28) Attaching the … Read more

Java FileInputStream ObjectInputStream reaches end of file EOF

readObject() doesn’t return null at EOF. You could catch the EOFException and interpret it as EOF, but this would fail to detect distinguish a normal EOF from a file that has been truncated. A better approach would be to use some meta-data. That is, rather than asking the ObjectInput how many objects are in the … Read more

getResourceAsStream() vs FileInputStream

The java.io.File and consorts acts on the local disk file system. The root cause of your problem is that relative paths in java.io are dependent on the current working directory. I.e. the directory from which the JVM (in your case: the webserver’s one) is started. This may for example be C:\Tomcat\bin or something entirely different, … Read more