Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How not to hard-code file location in java?

 
Sandeep Swaminathan
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?

 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use Properties File or log4j (properties)
 
Sandeep Swaminathan
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yep! But I was asked to use only flat files..
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3076
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20529
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The properties file should only contain the location for the actual log file.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
salvin francis
Bartender
Posts: 1274
10
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What happens if you do this :


 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic