【发布时间】:2012-10-21 08:28:46
【问题描述】:
我想将 HashSet 存储到服务器目录。 但我现在只能将其存储在 .bin 文件中。 但是如何将 HashSet 中的所有 Key 打印到 .txt 文件中呢?
static Set<String> MapLocation = new HashSet<String>();
try {
SLAPI.save(MapLocation, "MapLocation.bin");
} catch (Exception ex) {
}
public static void save(Object obj, String path) throws Exception {
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(
path));
oos.writeObject(obj);
oos.flush();
oos.close();
}
【问题讨论】:
-
为什么不遍历集合并将所有字符串写入文件?另外,SLAPI 是什么类型的对象?
-
HashSet 中的键是什么意思?
标签: java string file-io set hashset