Help:Can not find the file in jar!

Hello everyone:
I build a project using Netbeans 5.0 and make a jar file with it...
The code in the project as follows will throw an exception described that it can not find the file named datasource-config.xml
String dataFilePath = getClass().getResource(dataFile).getPath();
//System.out.println("filepath:"+dataFilePath);
InputStream input = new FileInputStream(dataFilePath);
when I run the project with the main() function as an entry it works perfectly and output:
filepath:/C:/projects/java_project/search/build/classes/com/cn/wxjt/lucene/config/datasource-config.xml
But when I compressed the project with jar and run it , it will show:
filepath:file:/C:/projects/java_project/search/dist/search.jar!/com/cn/wxjt/lucene/config/datasource-config.xml
there is a (!) between search.jar and /com/cn/wxjt...
I dont know why I generate a ! symbol in the file path... Is it cause the exception->
java.io.FileNotFoundException: file:\C:\projects\java_project\search\dist\search.jar!\com\cn\wxjt\lucene\config\datasource-config.xml
If you have any idea, plz tell me.
Thank you and best wishes to you !
:)

If the file you want to read is in your jar file, use
getClass ().getResourceAsStream
(relative_path_file_name)Hope that help,
Jackhey jack i want to open the file as new File
i m using this.getClass().getResource("resource/backend.xml");
the resource is the directory inside the jar file.
when i prints the url it shows:
the jar file is in the WORK directory
URL : jar:file:/home/neeraj/WORK/show.jar!/resource/backend.xml
now when i creates new File using the url.getFile() method the file does not exist.
although the same programs runs well when i uses the InputStream
so plz tell me cant I create a new File from the above method????
thanks in advance
with regards
neeraj

Similar Messages

Maybe you are looking for

  • Full Page Background in Internet Explorer 8 and Below

    I am currently trying to achieve a full page background image using the method found here: http://cookbooks.adobe.com/post_Scale_Background_image_to_browser_size-17590.html Everything works fine in FF, Chrome, and Safari, but when I preview the page

  • Gross invoice amount and net invoice amount

    Hi Experts, Can anybody tell me which is the gross invoice amount and net invoice amount field. From which table can I get them? I need to fetch Gross invoice amount and net invoice amount for both PObased invoice and non-PO based invoice against a c

  • Trouble upgrading to 10.6.1

    Hi all, I'm having trouble upgrading to iTunes 10.6.1.  Earlier today, I opened iTunes, and received an error message that "iTunes Library.itl cannot be read because it was created by a newer version of iTunes."  Still not sure why this happened. I f

  • Mpd update error

    just updated mpd and i keep getting a connection refused message when trying to start ncmpcpp. anyone else see this?

  • It will not let me re-install.

    My MG6220 printer keeps giving me an error that my Printer is currently in use.  It is not I have unistalled it and will not let me re-install the software.