Java编写增删改查,不使用数据库(用IO,或者集合框架),请大家帮小弟弄一下,谢谢

解决方案 »

  1.   

    jdk有现成的集合类,可以随心所欲很开心地增删改查。
      

  2.   

    不能使用数据库,可以使用 XML + XQJ + XQuery + XQuery Update
      

  3.   

    import java.util.*;
    public class EmployeeManage {
        HashMap m;
        public EmployeeManage(){
         m=new HashMap();
        }
        //加入员工
        public void addEmployee(Employee e){
         m.put(e.getSno(), e);
        }
        //查找员工
        public void inforEmp(String sno){
         if(m.containsKey(sno)){
         System.out.println("找到该员工.");
         Employee e=(Employee)m.get(sno);
         System.out.println(e.toString());
         }
         else 
         System.out.println("不存在该员工!");
        }
        //遍历所有员工
        public void bianliEmp(){
         Iterator it=m.entrySet().iterator();
         while(it.hasNext()){
         Map.Entry map=(Map.Entry)it.next();
         System.out.println(map.getValue().toString());
         }
        }
        //修改员工工资
        public void newprice(String sno,double price){
         if(m.containsKey(sno)){
         Employee e=(Employee)m.get(sno);
         e.setPrice(price);
         }
        }
        //删除员工信息
        public void removeEmp(String sno){
         if(m.containsKey(sno)){
         m.remove(sno);
         }
        }
    }
      

  4.   

    你的IO是什么意思?
    用io流写道文件里面存储吗?
    可以,但是要实现serializabled接口!
      

  5.   

    package com.fendou;import java.io.*;public class StudentDemo {
    public static void main(String args[]) {
    StudentManage sm=new StudentManage();
    File f = new File("C:\\Documents and Settings\\Administrator\\桌面\\1.txt");
    FileInputStream in = null;
    FileOutputStream out = null;
    ObjectInputStream os = null;
    ObjectOutputStream outs = null;
    BufferedReader b = new BufferedReader(new InputStreamReader(System.in)); try {
    out = new FileOutputStream(f);
    outs = new ObjectOutputStream(out);
    in = new FileInputStream(f);
    os = new ObjectInputStream(in);
    while (true) { System.out.println("************************menu************************");
    System.out.println("     1:增加学生信息             2:显示学生信息      ");
    System.out.println("     3:查找学生信息             4:修改学生分数     ");
    System.out.println("     5:删除学生信息             6:退出系统          ");
    System.out.println("****************************************************");
    System.out.println("  请输入你选择的功能(1~6):");
    String s1 = b.readLine();
    if (s1.equals("1")) {
    System.out.println("请输入学生学号:");
    String sno = b.readLine();
    System.out.println("请输入学生姓名:");
    String sname = b.readLine();
    System.out.println("请输入学生分数:");
    double score = Double.parseDouble(b.readLine());
    Student student = new Student(sno, sname, score);
    outs.writeObject(student);
    Student s;
    try {
    s = (Student)os.readObject();
    sm.addEmployee(s);
    } catch (ClassNotFoundException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }

    } else if (s1.equals("2")) {
    sm.bianliEmp();
    } else if (s1.equals("3")) {
    System.out.println("请输入学生学号:");
    String sno = b.readLine();
    sm.inforEmp(sno); } else if (s1.equals("4")) {
    System.out.println("请输入要修改学生的学号:");
    String sno=b.readLine();
    System.out.println("请输入新分数:");
    double score=Double.parseDouble(b.readLine());
    sm.newprice(sno, score);
    } else if (s1.equals("5")) {
    System.out.println("请输入要删除学生的学号:");
    String sno=b.readLine();
                        sm.removeEmp(sno);
    } else if (s1.equals("6")) {
    System.exit(0);
    } }
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    }}
    学生类自己写,但要实现serializabled接口。
      

  6.   

    把数据保存成CSV-like 的格式。一行保存一条记录。一次读/写一行。