我试图使用以下代码将 Hashset(整数)导出到文件,但似乎无法使用 outputStream.write()
完成此操作。这里或谷歌上似乎没有任何涵盖此问题的早期问题,这令我感到惊讶。
在 Activity 中定义了 Hashset 如下:
HashSet<Integer> set = new HashSet<Integer>();
并且方法是:
public void savehashset(){
String filename="storedhashset.set";
File storedhashset = new File(getFilesDir(), filename);
FileOutputStream outputStream;
try {
outputStream = openFileOutput(filename, Context.MODE_PRIVATE);
outputStream.write(set);
outputStream.close();
} catch (Exception e) {
e.printStackTrace();
}