我有以下代码将Object保存到文件,问题是我想将其保存为CP1252并作为对象,但它只允许我保存为String
BufferedWriter output = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file_path), "Cp1252"));
output.write(object_root.toString());
output.close();
保存为字符串时,在加载对象(ArrayList<StringBuffer>
时)处理其内容时会出现问题
当我从文件中加载对象时,它给了我一个字符串,我无法想办法让它再次成为ArrayList<StringBuffer>
,我试过了:
BufferedReader input = new BufferedReader(new InputStreamReader(new FileInputStream(file_path), "Cp1252"));
Object object_root = input.read();
String object_root_str = object_root.toString();
String[] array = object_root_str.split(".,");
ArrayList<String> arrayString = new ArrayList<String>(Arrays.asList(array));
然后
ArrayList<StringBuffer> arraySB = (ArrayList<StringBuffer>)arrayS;
但它表示无法转换
我需要知道是否有办法使用BufferedWriter(因为我需要它为CP1252)将ArrayList<StringBuffer>
保存为对象或ArrayList<StringBuffer>
。或者我需要找到一种方法让我保存的字符串再次成为ArrayList<StringBuffer>