Win a copy of Terraform in Action this week in the Cloud forum!
  • 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 Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Reading from a file located in same folder as my JAR file.

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I have my Netbeans Project after building of which creates a JAR file in the "dist" folder.
Now i want to read some settings stored in a "settings.ini" which i pasted in the same directory as the JAR file.

In my code i give directly, the name of the file to read from in the File Input stream. This does not work, and gives error saying cannot read from file, there is a path resolvnig problem...

What is the correct code notation to read from the file?

Following is the code:
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
On File(Settings.ini), did you mean

instead?

 
Krishna Komarpant
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

r035198x wrote:On File(Settings.ini), did you mean

instead?



Oh yes... I apologize for that. It was a typo, i was in haste so did not realize that mistake.

By the way, i figured it out..
I kept the "Settings.ini" file in the Project Home folder and gavethe same format statement in the code

and continued with my file reading code, and it works perfect.

Thanks anyways!
 
Ranch Hand
Posts: 225
IBM DB2 Eclipse IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Krishna

Could you please try this solution




If you ReadFromFile is packed as jar in name myJar.jar and place Settings.ini in same folder

Above code will read properties file "Settings.ini" .
 
Krishna Komarpant
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes this will work, bu i realised that i was making my code to commit suicide..

When you write the above code, it takes the base directory for the "Settings.ini" file to be in "projectHomeFolder/build/" directory, which is always deleted and re-created when you build you whole project.

As i have mentioned in the previous post, the solution was to paste the "Settings.ini" file in the "ProjectHomeFolder"

 
Ranch Hand
Posts: 174
Java ME Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
getResourceAsStream()

http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Class.html#getResourceAsStream(java.lang.String)
 
reply
    Bookmark Topic Watch Topic
  • New Topic