| Author |
How not to hard-code file location in java?
|
Sandeep Swaminathan
Ranch Hand
Joined: Apr 23, 2008
Posts: 52
|
|
I'm using a Logger class to log the errors occuring. But while creating a file I'm hard-coding the file location. which I'm not supposed to do. How do I specify a path which I don't want to hard-code in java?
|
Music is all around us. All you have to do is just LISTEN to it,
Sandeep Swaminathan
|
 |
Seetharaman Venkatasamy
Ranch Hand
Joined: Jan 28, 2008
Posts: 5575
|
|
|
Use Properties File or log4j (properties)
|
 |
Sandeep Swaminathan
Ranch Hand
Joined: Apr 23, 2008
Posts: 52
|
|
|
Yep! But I was asked to use only flat files..
|
 |
Seetharaman Venkatasamy
Ranch Hand
Joined: Jan 28, 2008
Posts: 5575
|
|
Sandeep Swaminathan wrote:But I was asked to use only flat files..
what do you mean by flat files ? if you dont want to use properties file then go for Constant class
example:
Hope this helps
|
 |
Mike Simmons
Ranch Hand
Joined: Mar 05, 2008
Posts: 2782
|
|
Hm, I would describe that Constants class as being hard-coded. You can't change the file location without recompiling. That's presumably what Sandeep is trying to avoid.
But Sandeep, I would say that a properties file is a flat file. To most of us, anyway. And a log4j.properties file is a kind of properties file, thus also a flat file. So probably this is what you need to do. If you think that's incorrect, then you should answer SV's question: what do you mean by flat files?
|
 |
Seetharaman Venkatasamy
Ranch Hand
Joined: Jan 28, 2008
Posts: 5575
|
|
Flat file contains one record per line . single field can be separated by delimiters such as commas,etc...
properties file contains key/value per line . so as Mike mentioned properties file is a Perfect Flat File
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
|
The properties file should only contain the location for the actual log file.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
Seetharaman Venkatasamy
Ranch Hand
Joined: Jan 28, 2008
Posts: 5575
|
|
|
 |
salvin francis
Ranch Hand
Joined: Jan 12, 2009
Posts: 915
|
|
What happens if you do this :
|
My Website: [Salvin.in] Cool your mind:[Salvin.in/painting] My Sally:[Salvin.in/sally]
|
 |
 |
|
|
subject: How not to hard-code file location in java?
|
|
|