Results 1 to 14 of 14
- 07-29-2011, 09:05 AM #1
Member
- Join Date
- Jan 2011
- Posts
- 14
- Rep Power
- 0
load pdf from jar file (help please)
hello ,,, i have problem please ,,, it is illustrated in the picture ,,, please help me if you can ,, thanks alot

//================================================== ========================
public void doOpen(String name) {
URL url=getClass().getResource(name);
try {
URI uri=null;
uri=url.toURI();
File file =new File(uri);
openFile(file);}
catch (Exception ex) {}}
//================================================== ========================Last edited by 3ammary; 07-29-2011 at 07:04 PM.
- 07-29-2011, 09:32 AM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
Wow.
That has to be a contender for the Least Amount Of Useful Information In An OP award...
- 07-29-2011, 02:05 PM #3
To read "files" from a jar file you can use the getResource() method to get a URL to read. Or getResourceAsStream to get a stream.
- 07-29-2011, 07:04 PM #4
Member
- Join Date
- Jan 2011
- Posts
- 14
- Rep Power
- 0
method
i use this method and still got same problem
//================================================== ========================
public void doOpen(String name) {
URL url=getClass().getResource(name);
try {
URI uri=null;
uri=url.toURI();
File file =new File(uri);
openFile(file);}
catch (Exception ex) {}}
//================================================== ========================
- 07-29-2011, 07:07 PM #5
Please post the full text of the error messages.still got same problem
What does the openFile() method do?
The resource is not a file. It is part of a jar file.
For debugging, print out the values of the variables: url and uri
- 07-29-2011, 07:18 PM #6
Member
- Join Date
- Jan 2011
- Posts
- 14
- Rep Power
- 0
no error it just don't open the pdf when the jar file is created....
=====================
com.sun.pdfview.PDFViewer
public void openFile(File file) throws IOException
Open a specific pdf file. Creates a DocumentInfo from the file, and opens that.
Note: Mapping the file locks the file until the PDFFile is closed.
Parameters:
file - the file to open
Throws:
IOException
======================
com.sun.pdfview.PDFViewer
public void openFile(URL url) throws IOException
open a URL to a PDF file. The file is read in and processed with an in-memory buffer.
Parameters:
url
Throws:
IOException
====================
The resource is not a file. It is part of a jar file.====>yes it is
==================
url and ur ,, i print them after i converted them to string
file:/C:/onecopy/pdf%20viewr+zip%20code/build/classes/com/sun/pdfview/1.pdf
file:/C:/onecopy/pdf%20viewr+zip%20code/build/classes/com/sun/pdfview/1.pdf
==================
the problem is here
http://hostphotoshere.com/data/4d0/4...90baf31e7a.jpg
- 07-29-2011, 07:46 PM #7
Member
- Join Date
- Jan 2011
- Posts
- 14
- Rep Power
- 0
waiting for help , thanks alot
- 07-29-2011, 07:49 PM #8
Please explain the contents of the jar file and what you are are going to do when you are able to read the bytes of the pdf "file" that is in the jar file.
What program is trying to read the contents of the jar file? Is that program's class file in the jar file or outside of it?
If the program that is trying to read the jar file is not in the jar file, then you need to use the ZipFile or JarFile class to get to the contents of a jar file.
Were the URL and URI you printed from executing the program that is contained in the jar file?
- 07-29-2011, 07:57 PM #9
Member
- Join Date
- Jan 2011
- Posts
- 14
- Rep Power
- 0
i am uploading the whole project
- 07-29-2011, 08:01 PM #10
I have no idea what you are trying to do. Why use a jar file? Why not put all the files into a zip file or a rar file?
What does "uploading" mean? I understand uploading to mean copying a file from a pc to a website. Is that it?
Please explain the contents of the jar file and what you are are going to do when you are able to read the bytes of the pdf "file" that is in the jar file.
What program is trying to read the contents of the jar file? Is that program's class file in the jar file or outside of it?
- 07-29-2011, 08:11 PM #11
Member
- Join Date
- Jan 2011
- Posts
- 14
- Rep Power
- 0
dear norm ,
the program is pdf reader ,,,
i want the pdf reader and the pdf file i want to read are in one file ,,, (jar) file ,,, i don't want the pdf alone and the jar file of the reader alone ,, so i want when i open the jar file ,,, it opens the reader file and the pdf file is loaded automatically ...the problem is it runs perfect when it is in netbeans ,, but when i create jar file ,,, it runs only the reader (without automatic loading ) the pdf ,,,, the whole project is here ....
a.rar
thanks alot ,,, waiting for your reply
- 07-29-2011, 08:15 PM #12
If the 'pdf reader' is not a java class, then I have no idea how it can read a "file" that is in a jar file.
If it is a java class, what methods does it have for reading the bytes of the pdf file? The pdf reader needs to be able to read the bytes from an InputStream. The InputStream is returned by the getResourceAsStream method
- 07-29-2011, 08:20 PM #13
Member
- Join Date
- Jan 2011
- Posts
- 14
- Rep Power
- 0
i have uploaded the whole file ,, could you please take alook of it,if you are free, thanks alot
- 07-29-2011, 08:23 PM #14
If you need help with your code, please make a SSCCE to show your problem and post it here on the forum.
You need to read the following and respond to it. It may not be possible for your idea to work.
If the 'pdf reader' is not a java class, then I have no idea how it can read a "file" that is in a jar file.
If it is a java class, what methods does it have for reading the bytes of the pdf file? The pdf reader needs to be able to read the bytes from an InputStream. The InputStream is returned by the getResourceAsStream method
Similar Threads
-
Load RDF file
By priyam_maheshwari in forum Advanced JavaReplies: 2Last Post: 06-27-2011, 10:54 PM -
Load file with a lot or lines.
By juamd in forum Advanced JavaReplies: 9Last Post: 04-26-2011, 07:41 PM -
file load
By myka in forum Advanced JavaReplies: 1Last Post: 04-03-2010, 08:42 PM -
Load file in GUI instead of notepad
By Kruptein in forum AWT / SwingReplies: 1Last Post: 08-08-2009, 05:57 PM -
Not able to load a properties file
By Happy9959 in forum New To JavaReplies: 12Last Post: 07-29-2008, 07:15 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks