how can we read a .pdf file in java
read a file
Collapse
X
-
like any other file. (see code below)Originally posted by litunhow can we read a .pdf file in java
But maybe you want tor rephrase your question, because you want to display it on screen in java, or convert it to different format, or copy it? I am just curious about your question, because you mention ".pdf" which has nothing to do with "reading" the file.
here is how to read a file:
Code:File sourceFile = new File(sourceFileName); if (! sourceFile.exists()) throw new IOException("[ERROR ]: no such source file: " + sourceFileName); if (! sourceFile.isFile()) throw new IOException("[ERROR]: can't copy directory: " + sourceFileName); if (! sourceFile.canRead()) throw new IOException("[ERROR]: source file is unreadable: " + sourceFileName); FileInputStream sourceStream = null; byte[] buffer = new byte[file.length()]; sourceStream = new FileInputStream(sourceFile); int bytesRead = sourceStream.read(buffer); -
To do what? If you are just accessing it to re-name it, or move it the above post example will work. If you actually want to modify a PDF you will want to look at the iText dev library.Originally posted by litunhow can we read a .pdf file in javaComment
-
Here's a suggestion that will help you, not only in this forum, or in learning Java, or even programming, but throughout your entire life: when you ask a question, don't assume people can read your mind. Explain your context. What is your goal? What are you trying to do and why?Originally posted by litunhow can we read a .pdf file in javaComment
-
Like has already been pointed out, the purpose is the most important thing. e.g Reading a file to display the text in it to the screen is done differently for different file formats.Originally posted by hsnhi
have even tried to read a PDF file before you ask here.
i think it should work normally. because you can read any type of file by java and its classes.
you can read html, word documents, in,txt, and so on. why will it stop at PDF
Good Luck
hsnComment
Comment