Buffered Reader:使用 HashMap 读取并保存一行的某些部分(在 java?)
Buffered Reader: read and save certain parts of a line with HashMap (in java?)
我有一个包含这两行的文本文件:
PC Looks like the killer was panicking and searched for help as soon as he could......
Cupboard I understand this is quite the scene to stomach for your first mystery
使用 BufferedReader,我想将第一个单词(例如 PC)保存为 HashMap 键,将以下句子保存为它的值。
我在网上搜索了这个问题的答案,我发现了一个由 Rumen 创建的问题,它的回答与我正在寻找的非常相似。但是,他们使用了 line.split() ,这只有在我有类似的东西时才有效:
PC On
因为那样会将 PC 保存为键,将 On 保存为值。其次,用户 funglejunk,另一个答案使用了 ProcessInformation(作为列表的参数),我还没有了解它(但会把它放在列表中!)
是我要参考的答案。
感谢所有帮助!
String key = line.substring(0, line.indexOf(' '));
String value = line.substring(line.indexOf(' ') + 1);
我有一个包含这两行的文本文件:
PC Looks like the killer was panicking and searched for help as soon as he could......
Cupboard I understand this is quite the scene to stomach for your first mystery
使用 BufferedReader,我想将第一个单词(例如 PC)保存为 HashMap 键,将以下句子保存为它的值。
我在网上搜索了这个问题的答案,我发现了一个由 Rumen 创建的问题,它的回答与我正在寻找的非常相似。但是,他们使用了 line.split() ,这只有在我有类似的东西时才有效:
PC On
因为那样会将 PC 保存为键,将 On 保存为值。其次,用户 funglejunk,另一个答案使用了 ProcessInformation(作为列表的参数),我还没有了解它(但会把它放在列表中!)
感谢所有帮助!
String key = line.substring(0, line.indexOf(' '));
String value = line.substring(line.indexOf(' ') + 1);