aspose file tools*
The moose likes Java in General 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 » Java in General
Bookmark "Properties File?" Watch "Properties File?" New topic
Author

Properties File?

Pat Peg
Ranch Hand

Joined: Feb 04, 2005
Posts: 194
I�m trying to use Properties for the first time and I am running into an error. Even when I cut and paste the example I get the same error. Here is the code.

Error = �Syntax error on token(s);misplaced constructor
�Sysntax error on �load� = expected after this token
These are both for the second line.
Any ideas?

The reason I am using a properties file (and I hope I am using it for the right reasons) is to store my database connections info such as user name, etc. Is this a correct and proper use of Properties?

I am using java 1.5 if that is significant.

Thanks
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12835
    
    5
I can think of several ways for that statement to go wrong.
You are using a file name that implies the "current" directory - a practice that will surely result in trouble at some time.
If this was my problem I would first construct a File object and use the exists() and canRead() methods to be sure that the properties file is there.
Bill
Rick O'Shay
Ranch Hand

Joined: Sep 19, 2004
Posts: 531
If the file is not there it will tell you that and it's always safe, in fact recommended, to do what you are doing. When you do not specify a path, the directory of the current class is assumed, whether it's in a jar or not. Not sure I would call that the current directory but it's always safe to package properties that way:

../com/acme/rockets/Rocket.class
../com/acme/rockets/Trajectory.properties

Now, if you load from class Rocket you are guaranteed to find the Trajectory properties. If you use a file system path, now you are dependent on whether a jar was created, a war file for example.

I think there's something wrong with one of your property definitions. It's hard to mess that up however. Any key value pair works in several formats:

There are all equivalent:

range = 100
range:100
range: 100
range 100

Given that you have a JDBC driver string and such, I'm guessing that might be the problem.
Pat Peg
Ranch Hand

Joined: Feb 04, 2005
Posts: 194
Thanks for the input. Unfortunately I still have not found the answer. I put in the absolute path and I changed the values in the properties file to be just strings such as
OracleDriver = driver
It is still giving the same problems. I think it is something more involved because when I cut and paste the example of how to use propertie files into the code I get the exact same errors. I have seen very rarely where an actual example was coded wrong but I don�t think that is the case here.
Norm Radder
Ranch Hand

Joined: Aug 10, 2005
Posts: 690
    
    1
Could you post the contents of the properties file that you are reading?
If its a large file, strip it down to the minimum that causes the error and just post that.
Pat Peg
Ranch Hand

Joined: Feb 04, 2005
Posts: 194
sure. Its a simple file as I am trying to learn how to use this


I had taken out the actual info and tried it but it still isn't working.
[ August 23, 2005: Message edited by: Pat Peg ]
Norm Radder
Ranch Hand

Joined: Aug 10, 2005
Posts: 690
    
    1
Do you get the error using what you posted?
Could you copy and post the exact contents of the error message?
Its better if you copy and paste the exact message instead of typing it in.
Then we can see spelling errors etc that you might change.
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923


Error = �Syntax error on token(s);misplaced constructor
�Sysntax error on �load� = expected after this token

'Syntax error' looks much like an compile-time error - doesn't it?

The bare minimum to reproduce the bug is here (and nearly exactly what was posted):


I can see clearly now ...

The method-call dbProperties.load (...) needs to be in a method or in the constructor.

[ August 24, 2005: Message edited by: Stefan Wagner ]
[ August 24, 2005: Message edited by: Stefan Wagner ]

http://home.arcor.de/hirnstrom/bewerbung
Pat Peg
Ranch Hand

Joined: Feb 04, 2005
Posts: 194
Wow, thanks. That did it exactly
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12835
    
    5
When you do not specify a path, the directory of the current class is assumed, whether it's in a jar or not. Not sure I would call that the current directory but it's always safe to package properties that way:

I can't imagine where you got that zinger from.
The "current" directory I was talking about is what the operating system considers the user's current directory. FileInputStream creates a File object which uses that convention - which has nothing to do with where the class file was loaded from.
Bill
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Properties File?