• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

properties file

 
Ranch Hand
Posts: 1402
3
Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have a java application and I want read my properties file which is in the properties folder with name properties.properties.

My code is



I have try another one which is


Also the code I have is in the path /project/src/folder and the properties folder in /project/properties/properties.properties In the code I try to reach the file like this:

Thanks,
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Angus Ferguson wrote:Could anyone provide code, please?. Because I have tried code from the net but it doesn't works


We don't do that here. Folks will help you figure out what you are doing wrong, but nobody should simply provide you a complete and full solution.
 
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Angus Ferguson wrote: Because I have tried code from the net but it doesn't works


Edited: Sorry, didn't see all your code the first time.

Q. Are you getting FileNotFoundExcpetion or any other exceptions? Please provide details about what is wrong. Provide the stacktrace or whatever you have. If no exceptions are thrown then what is the problem? Where exactly does it fail and how do you determine that it failed?

p
 
Angus Ferguson
Ranch Hand
Posts: 1402
3
Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,


it seems that doesn´t find the properties file. No errors are thrown.

Thanks
 
fred rosenberger
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Angus Ferguson wrote:it seems that doesn´t find the properties file. No errors are thrown.


How can you tell when you have a line like this?

 
Angus Ferguson
Ranch Hand
Posts: 1402
3
Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When I run it it doesn´t throw errors. But in the file properties is nothing writen. I don´´t understand wht you mean.

Thanks
 
Marshal
Posts: 28226
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, read what Fred wrote. You have no idea if the code throws exceptions, because you have specifically written your code to ignore them if it does.
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Angus Ferguson wrote:When I run it it doesn´t throw errors. But in the file properties is nothing writen. I don´´t understand wht you mean.

Thanks



You can't know if there are any errors or not because you're doing this:



which says, "If an IOException happens, just ignore it and continue processing as if everything is fine, even though it's not. Don't even tell me about the problem; I don't want to know."

We don't catch exceptions to make the problem magically disappear. The exception mechanism with it's try/catch structure is there to allow us to separate our "happy path" code from the code we have to write to deal with things going wrong. We still have to deal with the problems when they occur though.
 
Paul Witten
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Angus Ferguson wrote:it seems that doesn´t find the properties file. No errors are thrown.


The guys are right, Angus. The empty catch{} is going to hide problems. You will never see an exception. I think if you print a stacktrace there you will find a problem.

If FileNotFound is the problem then try using an absolute path like c:\dev\java\projects\project1\properties.properties instead of the relative path. Relative path is better in the real world, but not if it has too many or not enough ..\.

Guys, anybody know whether relative path root is the dir where the runtime is invoked rather than the root of the project? Something tells me that it uses the dir where you invoke the runtime.
 
Paul Clapham
Marshal
Posts: 28226
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Witten wrote:Guys, anybody know whether relative path root is the dir where the runtime is invoked rather than the root of the project? Something tells me that it uses the dir where you invoke the runtime.



No, the root for relative paths is a value called the Current Working Directory. You set that value via the "cd" command (no matter whether you're using Windows or some Unix variety). I'm not sure what you mean by "the dir where you invoke the runtime", so I can't say if that's right or not. If you meant "the directory where the java.exe runtime is located" then no, that isn't right. But I suspect you didn't mean that.
 
Paul Witten
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:No, the root for relative paths is a value called the Current Working Directory. You set that value via the "cd" command (no matter whether you're using Windows or some Unix variety). I'm not sure what you mean by "the dir where you invoke the runtime", so I can't say if that's right or not. If you meant "the directory where the java.exe runtime is located" then no, that isn't right. But I suspect you didn't mean that.


Hi Paul (another of the many Pauls around here). No I meant invoking java from a directory, say, one or two levels above the root of the project. I think that is then the Current Working Directory, right? That would make a relative path fail I think. Not relevant to the OP's problem I guess, but I often wondered whether relative paths could be made to fail that way (without testing it myself, har.)

 
Angus Ferguson
Ranch Hand
Posts: 1402
3
Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My intention is using a properties file in order to make my jsp values configurable. I mean if I want change the name of one value my jsp I would prefer go to my properties and change it from there that change it in code.

For example;

Name: Angus

Angus would came from the DB and Name from my properties

Could somebody give any advice, please?




Thanks
 
Paul Clapham
Marshal
Posts: 28226
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Witten wrote:No I meant invoking java from a directory, say, one or two levels above the root of the project. I think that is then the Current Working Directory, right?



That would depend on what "project" means. CWD is a concept which belongs to the operating system, and each process running in the system has its own CWD. Furthermore, CWD is one of the environment variables, so a process can't change its own CWD.

Therefore if you're talking about "projects" in an IDE like Eclipse or Netbeans, then the IDE will have a working directory. Obviously, then, the working directory can't be related to any of the projects. (Remember that the CWD is set before the IDE starts, since it's part of the process's environment.)

And anyway, writing your code to act as if the CWD was the root of the project, or something like that, would be a bad idea. That would be an assumption which might not correspond to the actual situation when you tried to run your application outside the IDE.
 
Paul Clapham
Marshal
Posts: 28226
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Angus Ferguson wrote:My intention is using a properties file in order to make my jsp values configurable.



So this question is about JSP? You should have mentioned that earlier.

The standard way to provide properties to a JSP is by setting context parameters in your web.xml file. These then become application-level properties of the web application.
 
Angus Ferguson
Ranch Hand
Posts: 1402
3
Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But I mean not add new properties to a jsp, I mean to use a simple properties file in order to change some labels in my jsp thats all I am looking the simplest way. Any advice please?

Thanks
 
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If it’s a JSP question, it ought to be in that forum.
 
Without deviation from the norm, progress is not possible - Zappa. Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic