| 12345678910111213141516171819202122232425262728293031 | package J20250802.demo04;import java.io.*;import java.util.HashSet;import java.util.Map;import java.util.Set;import java.util.TreeSet;/** * @author WanJl * @version 1.0 * @title PersonService * @description * @create 2025/8/2 */public class PersonService {    private static TreeSet<Person> set=new TreeSet<>();    public static boolean saveToSet(Person p){        return set.add(p);    }    public static boolean saveToFile(Map<String,Person> set)  {        try{            FileOutputStream fos = new FileOutputStream("D:/abc.txt");            ObjectOutputStream oos=new ObjectOutputStream(fos);            oos.writeObject(set);            return true;        }catch (IOException e){            return false;        }    }}
 |