aspose file tools*
The moose likes JSP and the fly likes properties file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "properties file" Watch "properties file" New topic
Author

properties file

Isaac Ferguson
Ranch Hand

Joined: Jun 22, 2012
Posts: 389
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,
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11475
    
  16

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.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Paul Witten
Ranch Hand

Joined: Oct 10, 2012
Posts: 86
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
Isaac Ferguson
Ranch Hand

Joined: Jun 22, 2012
Posts: 389
Hi,


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

Thanks
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11475
    
  16

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?

Isaac Ferguson
Ranch Hand

Joined: Jun 22, 2012
Posts: 389
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
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18887
    
    8

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.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

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

Joined: Oct 10, 2012
Posts: 86
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
Bartender

Joined: Oct 14, 2005
Posts: 18887
    
    8

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

Joined: Oct 10, 2012
Posts: 86
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.)

Isaac Ferguson
Ranch Hand

Joined: Jun 22, 2012
Posts: 389
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
Bartender

Joined: Oct 14, 2005
Posts: 18887
    
    8

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
Bartender

Joined: Oct 14, 2005
Posts: 18887
    
    8

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.
Isaac Ferguson
Ranch Hand

Joined: Jun 22, 2012
Posts: 389
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
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39793
    
  28
If it’s a JSP question, it ought to be in that forum.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: properties file