aspose file tools*
The moose likes Beginning Java and the fly likes Read *.sql file from the jar file...? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Read *.sql file from the jar file...?" Watch "Read *.sql file from the jar file...?" New topic
Author

Read *.sql file from the jar file...?

prabhu pandurangan
Ranch Hand

Joined: May 23, 2008
Posts: 120
Hi Members,

I have a jar file in which i have a directory structure "db/ms/dml/database.sql" but when i tried to read the file.... im getting some exception as... The file is not found at the path specified...

Please help me in this

Regards,
Prabhu.
Mark Vedder
Ranch Hand

Joined: Dec 17, 2003
Posts: 624

Can you please post your code and the error you are getting so we can better assist you.

You can take a look at the getResource(String) and getResourceAsStream(String) methods in the ClassLoader class.

The Smartly load your properties articles shows some different ways to load properties files including using the getReousrce methods. Any file, including an sql file, could be loaded in a similar manner.
prabhu pandurangan
Ranch Hand

Joined: May 23, 2008
Posts: 120
This is the exception is get:

Exception in thread "main" com.util.datamigrationtool.DataMigration
Exception: File not found in the path specified. \database\masterscript\migration\Dml.sql (The system cann
ot find the path specified)
at com.util.migrationtool.DataMigrationProcess.main(Dat
aMigrationProcess.java:133)

Regards,
Prabhu
Mark Vedder
Ranch Hand

Joined: Dec 17, 2003
Posts: 624

Can you post your code - at least the part where you try to load the file? From the exception, it looks as if you are might be trying to load the file directly.

Did you read the API documents and article I listed? Did those help any?

As some guidance, you'll need to use either the ClassLoader.getResource(String) method to get a URL to the file or the ClassLoader.getResourceAsStream(String) method to get an InputStream. When you enter the resource name, enter it with the path. For example: this.getClass().getClassLoader().getResource("db/ms/dml/database.sql").

If you use the getResource() method, you'll get a URL back. Convert that URL to a URI. You can then use the File(URI uri) constructor to create a File.

If you use the getResourceAsStream() method, you can use that InputStream in constructing a Reader or some other IO Class to read the file.
prabhu pandurangan
Ranch Hand

Joined: May 23, 2008
Posts: 120
Mark,


Thank you very much, Mark.

Let me work on this and let you know the status.... Ya i looked through the API, but i have to work on it.
prabhu pandurangan
Ranch Hand

Joined: May 23, 2008
Posts: 120
Thank you very much mark.

I could read the files from jar file.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Read *.sql file from the jar file...?