我有哈希表 html 内容是 url 字符串的 html 字符串。 我想将 hastable 写入 .text 文件。
谁能提出解决方案?
最佳答案
每个条目一行,两个字符串用逗号分隔怎么样?有点像:
"key1","value1"
"key2","value2"
...
"keyn","valuen"
保留引号,您也可以写出引用空条目的键,例如
"key", null
要实际生成表格,您可能需要使用类似于以下的代码:
public void write(OutputStreamWriter out, HashTable<String, String> table)
throws IOException {
String eol = System.getProperty("line.separator");
for (String key: table.keySet()) {
out.write("\"");
out.write(key);
out.write("\",\"");
out.write(String.valueOf(table.get(key)));
out.write("\"");
out.write(eol);
}
out.flush();
}
关于java - 如何将哈希表<string, string>写入文本文件,java?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2786038/