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 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
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:
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.
Joined: Feb 04, 2005
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.
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.
Joined: Feb 04, 2005
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 ]
Joined: Aug 10, 2005
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.
Author and all-around good cowpoke
Joined: Mar 22, 2000
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