I have a bunch of questions and answers that I need to store in a java .properties file. How can I do this easily?
I was thinking something like
faq.question.1 = This is question 1.
faq.question.2 = This is question 2.
faq.question.3 = This is question 3.
faq.answers.1 = This is answer 1.
faq.answers.2 = This is answer 2.
faq.answers.2 = This is answer 3.
Is this the best way to store the questions/answers in a properties file? Can I use numbers to delineate between the different questions/answers?
Your approach will work.
However, assuming:
...consider using the question as the key:
question=answer
If you intend to hand-edit these files be aware of the requirements of the file format. For the question Question: 'Hello World' == what in Japanese?
and the answer Answer — 'Hello World' == 'こんにちは世界'
the standard ISO-8859-1 stored form would be:
Question\:\ 'Hello\ World'\ \=\=\ what\ in\ Japanese?=Answer \u2014 'Hello World' \=\= '\u3053\u3093\u306B\u3061\u306F\u4E16\u754C'
Otherwise, consider a format like JSON or XML that allows greater correlation of question to answer and the addition of other properties:
[{
"question":"Question: 'Hello World' == what in Japanese?",
"answer":"Answer — 'Hello World' == 'こんにちは世界'"
}]
If you have a web-based application where FAQs need to be updated without rebuild and deployment overhead use a database.
If you have to store faq in properties file consider to change key with a question. Like this:
This is question 1. = This is answer 1.
This is question 2. = This is answer 2.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.