Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

what is java's equivalent to c/c++ string table resource files

 
Nathan Tran
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone tell me what is java's equivalent to c/c++ string table resource files? I want to write a logfile scanner that takes it's input parameter from either a string file/table. The scanner reads an error string from a file/table, searches through the log file for that error string; if not found, it reads the next error string from the file/table, searches for that string in the file; etc., until there's no more error strings to read from the file/table.
I heard a properties file could be a potential candidate. Can anyone provide me an example of what a java properties file of this type would look like. I'm interested in generating something like...
error1=Error:*failed.
error2=Error: Unable to*
error3=The system cannot find the file specified.
error4=Compile Error in File
Thanks so much in advance!!!
 
Karthik Guru
Ranch Hand
Posts: 1209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Nathan Tran:
Can anyone tell me what is java's equivalent to c/c++ string table resource files? I want to write a logfile scanner that takes it's input parameter from either a string file/table. The scanner reads an error string from a file/table, searches through the log file for that error string; if not found, it reads the next error string from the file/table, searches for that string in the file; etc., until there's no more error strings to read from the file/table.
I heard a properties file could be a potential candidate. Can anyone provide me an example of what a java properties file of this type would look like. I'm interested in generating something like...
error1=Error:*failed.
error2=Error: Unable to*
error3=The system cannot find the file specified.
error4=Compile Error in File
Thanks so much in advance!!!

I guess you have answered your question.
Yeah properties files can be used and it will have exactly the same kind of entries you have.
<key1>=<value>
<key2>=<value>
Since properties inherit from hashtable, u can get the enumeration of the keys from the properties file.
Properties p = new Properties();
p.load(new FileInputStream(<something>.properties);
Enumeration e = p.keys();
///go ahead.
karthik.
 
Nathan Tran
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the quick response Karthik.
Out of curiousity, would a properties file be the best way to implement an error string table?
Thanks again. :-)
 
Karthik Guru
Ranch Hand
Posts: 1209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Nathan Tran:
Thanks for the quick response Karthik.
Out of curiousity, would a properties file be the best way to implement an error string table?
Thanks again. :-)

Infact we do it the same way @ our place to get the error codes out. So what we have is a MessageHandler class which reads in all the properties in the beginning when the server starts up.
Then we do
MessageHandler.getMessage(<key>);
We do this kind of a thing to store sql queries as well, so that there's a centralised place of storing the queries.
It looks decent to me :-)
karthik.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic