473,396 Members | 1,590 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

read a file

12
how can we read a .pdf file in java
Apr 8 '08 #1
5 1505
chaarmann
785 Expert 512MB
how can we read a .pdf file in java
like any other file. (see code below)

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:
Expand|Select|Wrap|Line Numbers
  1. File sourceFile = new File(sourceFileName);
  2.  
  3. if (! sourceFile.exists()) throw new IOException("[ERROR ]: no such source file: " + sourceFileName);
  4. if (! sourceFile.isFile()) throw new IOException("[ERROR]: can't copy directory: " + sourceFileName);
  5. if (! sourceFile.canRead()) throw new IOException("[ERROR]: source file is unreadable: " + sourceFileName);
  6.  
  7. FileInputStream sourceStream = null;
  8. byte[] buffer = new byte[file.length()];
  9. sourceStream = new FileInputStream(sourceFile);
  10.  
  11. int bytesRead = sourceStream.read(buffer);
Apr 8 '08 #2
pronerd
392 Expert 256MB
how can we read a .pdf file in java
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.
Apr 8 '08 #3
BigDaddyLH
1,216 Expert 1GB
how can we read a .pdf file in java
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?
Apr 8 '08 #4
hsn
237 100+
hi

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
hsn
Apr 9 '08 #5
r035198x
13,262 8TB
hi

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
hsn
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.
Apr 9 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: Yang Li Ke | last post by:
Hi guys! I have some datas that I must check everytime a visitor comes to my site What is better to do: 1- Read data from a file or 2- Read data from a mysql db Thank you
10
by: ZafT | last post by:
Thanks in advance for any tips that might get me going in the right direction. I am working on a simple exercise for school that is supposed to use read to read a file (about 10 MB). I am...
1
by: cnu | last post by:
My program generates a log file for every event that happens in the program. So, I open the file and keep it open till the end. This is how I open the file for writing: <CODE> public...
4
by: ESPN Lover | last post by:
Below is two snippets of code from MSDN showing how to read a file. Is one way preferred over the other and why? Thanks. using System; using System.IO; class Test { public static void...
8
by: a | last post by:
I have a struct to write to a file struct _structA{ long x; int y; float z; } struct _structA A; //file open write(fd,A,sizeof(_structA)); //file close
5
by: lovecreatesbea... | last post by:
The condition at line 31 is added to check if the program finished to read the whole file. Is it needed and correct? Thank you. #include <fstream> #include <iostream> #include <string> using...
0
by: lovecarole | last post by:
hi, i am the student who should write a program about reading wav file and do the DFT. actually i don't know how to read data of the wav song and save it into the array... if i want to read...
6
by: Thomas Kowalski | last post by:
Hi, currently I am reading a huge (about 10-100 MB) text-file line by line using fstreams and getline. I wonder whether there is a faster way to read a file line by line (with std::string line)....
9
by: flebber | last post by:
I was working at creating a simple program that would read the content of a playlist file( in this case *.k3b") and write it out . the compressed "*.k3b" file has two file and the one I was trying...
2
by: Kevin Ar18 | last post by:
I posted this on the forum, but nobody seems to know the solution: http://python-forum.org/py/viewtopic.php?t=5230 I have a zip file that is several GB in size, and one of the files inside of it...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.