• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

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

 
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 624
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 147
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 624
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 147
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 147
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you very much mark.

I could read the files from jar file.
reply
    Bookmark Topic Watch Topic
  • New Topic