我是

Java的新手我如何在HashMap中存储整数值数组,之后我将这个HashMap写入txt文件,但这并不重要.我可以存储单个字段,但不能存储数组.有任何想法吗 ?

public void salveazaObiectulCreat(String caleSpreFisier) {

HashMap map = new HashMap();

map.put (“Autorul”,numelePrenumeleAutorului);

map.put (“Denumirea cartii”,denumireaCartii);

map.put (“Culoarea cartii”,culoareaCartii);

map.put (“Genul cartii”,gen);

map.put (“Limba”,limba);

map.put (“Numarul de copii”,numarulDeCopii);

map.put (“Numarul de pagini”,numarulDePagini);

map.put (“Pretul cartii”,pretulCartii);

try {

File file = new File(caleSpreFisier);

FileOutputStream f = new FileOutputStream(file);

ObjectOutputStream s = new ObjectOutputStream(f);

s.writeObject(map);

s.close();

} catch(Exception e){

System.out.println(“An exception has occured”);

}

}


版权声明:本文为weixin_33694136原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/weixin_33694136/article/details/114660027