存储在字符串中
我在属性文件中的 3 个不同行中列出了 3 个不同的单词。 QWERT 警察 重要的是
我想读取该属性文件并将这 3 个单词存储在 String 中,而不是存储在由空格分隔的 aarylist 中。输出应该是这样的 String str = { QWERT POLICE MATTER}
现在我使用了以下代码并获得了单词之间没有空格的输出: 字符串 str = {QWERTPOLICEMATTER}。我应该对代码做什么来获取由空格分隔的单词的字符串结果。
FileInputStream in = new FileInputStream("abc.properties");
pro.load(in);
Enumeration em = pro.keys();
StringBuffer stringBuffer = new StringBuffer();
while (em.hasMoreElements()){
String str = (String)em.nextElement();
search = (stringBuffer.append(pro.get(str)).toString());
Possible Duplicate:
What's the most elegant way to concatenate a list of values with delimiter in Java?
I have 3 different words listed in property file in 3 different lines.
QWERT
POLICE
MATTER
I want to read that property file and store those 3 words in String, not in aarylist separated by whitespace. The output should look like this
String str = { QWERT POLICE MATTER}
Now I used the follwoing code and getting the output without white space in between the words:
String str = {QWERTPOLICEMATTER}. What should I do to the code to get the string result with words separated by whitespace.
FileInputStream in = new FileInputStream("abc.properties");
pro.load(in);
Enumeration em = pro.keys();
StringBuffer stringBuffer = new StringBuffer();
while (em.hasMoreElements()){
String str = (String)em.nextElement();
search = (stringBuffer.append(pro.get(str)).toString());
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试:
Try:
只需在循环中添加一个空格即可。请参阅下面的额外附录:
Just append a blank space in your loop. See the extra append below: