• Post Reply Bookmark Topic Watch Topic
  • New Topic

FileInputStream problem  RSS feed

 
ozhan kaya
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.I have some problem with my code.I put my properties file to same directory with my class.When i try to reach it that says System can't find File.I think the problem is realated to classpath but i am not sure at all.Can you help me please.

 
Rob Spoor
Sheriff
Posts: 21095
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use getClass().getResourceAsStream("newproperties.properties") instead.

File, FileInputStream, FileOutputStream and several other file related classes, work with the current folder. That's the folder where you were when you invoked the JVM. Usually, that's the base of your package tree.
 
ozhan kaya
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry for second question.But although reading file is okey, saving same properties files failed for same method.Could you help me furthermore please
 
Rob Spoor
Sheriff
Posts: 21095
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't write to resources.

Ideally the application path would be available like with programs written in Visual Basic (for instance), but that's not the case. What you can do is use a user-specific location to store your files:
You can then load from the resource first, then from the properties file. You save to the properties file:
 
Maruthi Janardhan
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can get the current working directory of the program even in Java just like VB app path: System.getProperty("user.dir");
 
Rob Spoor
Sheriff
Posts: 21095
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unlike in VB, that's not necessarily the root folder of your application. It's the folder where you started the application from. If you use an explicit class path to find your classes it will not be what you expected.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!