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

  • How to restore music on computer after new hard drive installed?

    had new hard drive installed and am not able to retrieve/find music that was backed up on my computer before new hard drive was installed.  Only music that was in the "cloud" was able to be retrieved. Any idea where it could be? Thanks!

  • Having problems switching itunes from pc to mac

    I downloaded the migration assitance and tried to use, but nothing happened. I then tried to use external storage to transfer my itunes from my pc to new mac and pc said that the itunes file was to large to download. I am stuck! Does anyone have an i

  • Itunes install fails

    I attempted an Itunes update and it failed. I attempted several days later with same results. Meantime Itunes no longer works. So I came to this site and tried to do a new install. During the install I kept getting the message "Service 'Apple Mobile

  • Making MySQL ORDER BY link dynamic in URL

    I would like to have a dynamic table sorted by a dynamic URL. I have found this script but I am not sure where I am meant to put the DECLARE? This is the MySql recordset: BEGIN DECLARE @SortOrder tinyint SET @SortOrder = 2 SELECT * FROM products WHER

  • NTSystem for Administrators only (on NT4)

    One more time this problem appears in the forum. Perhaps someone will answer this time. Simple application : public class TestNTUser { public static void main(String[] args) { System.out.println((new com.sun.security.auth.module.NTSystem()).getName()