当前位置: 代码迷 >> Java Web开发 >> 写了一段程序,还需要一个“文件读入的功能”,
  详细解决方案

写了一段程序,还需要一个“文件读入的功能”,

热度:280   发布时间:2011-06-22 15:10:19.0
写了一段程序,还需要一个“文件读入的功能”,
一下是代码,在“是否读入”下面帮忙写一下
程序代码:
import java.io.*;
import java.util.*;

import com.sun.xml.internal.bind.v2.runtime.unmarshaller.Loader;

public class Done {

    /**
     *
@param args
     
*/
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        String id;
        String name;
        String sex;
        String interestId = "";
        String interesttypes = "";
        List<Student> list = new ArrayList<Student>();
        Scanner sc = new Scanner(System.in);

        int choose;
        int flag;
        System.out.println("是否读入1\0:");
        flag=sc.nextInt();
        if(1==flag){
            //这个地方

        }

        while (true) {
      
            System.out.println("信息的录入(1)、修改(2)、删除(3)、查询(4)、保存(5),退出(6)输入需要的操作:");
            choose = sc.nextInt();
            switch (choose) {
            case 1:
                System.out.println("信息的录入");
                id = sc.next();
                name = sc.next();
                sex = sc.next();
                interestId = sc.next();
                interesttypes = sc.next();
                Student p = new Student(id, name, sex, interestId,
                        interesttypes);
                list.add(p);
                System.out.println("录入成功!");
                break;
            case 2:
                System.out.println("输入要修改的学号Id:");
                id = sc.next();
                System.out.println("请输入姓名,性别,和兴趣编号,兴趣类型");
                for (int i = 0; i < list.size(); ++i) {
                    if (list.get(i).getId().equals(id)) {
                        name = sc.next();
                        sex = sc.next();
                        interestId = sc.next();
                        interesttypes = sc.next();
                        list.get(i).modify(id, name, sex, interestId,
                                interesttypes);
                        System.out.println("修改成功");
                        break;
                    }
                }
                break;
            case 3:
                System.out.println("信息的删除,输入要删除的项目编号:");
                id = sc.next();
                for (int i = 0; i < list.size(); ++i) {
                    if (list.get(i).getId().equals(id)) {
                        list.remove(i);
                        break;
                    }
                }
                break;
            case 4:
                System.out.println("信息的查询,输入要查询的项目编号:");
                id = sc.next();
                for (int i = 0; i < list.size(); ++i) {
                    if (list.get(i).getId().equals(id)) {
                        list.get(i).print();
                    }
                }
                break;
            case 5:
                try {
                    FileWriter sw = new FileWriter("c:\\liuhui.txt", true);
                    for (int i = 0; i < list.size(); ++i) {
                        sw.write(list.get(i).id);
                        sw.write("\t");
                        sw.write(list.get(i).name);
                        sw.write("\t");
                        sw.write(list.get(i).sex);
                        sw.write("\t");
                        sw.write(list.get(i).interestId);
                        sw.write("\t");
                        sw.write(list.get(i).interesttypes);
                        sw.write("\n");
                    }
                    sw.close();
                } catch (Exception e) {
                    //e.printStackTrace();
                }
                break;
            case 6:
                return;

            default:
                System.out.println("输入有错误");
                break;

            }
        }
    }
}

public class Student {
    String id;
    String name;
    String sex;
    String interestId;
    String interesttypes;
    public Student(String id, String name, String sex, String interestId,
            String interesttypes) {
        super();
        this.id = id;
        this.name = name;
        this.sex = sex;
        this.interestId = interestId;
        this.interesttypes = interesttypes;
    }
    public String getId() {
        return id;
    }
    public void setId(String id) {
        this.id = id;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getSex() {
        return sex;
    }
    public void setSex(String sex) {
        this.sex = sex;
    }
    public String getInterestId() {
        return interestId;
    }
    public void setInterestId(String interestId) {
        this.interestId = interestId;
    }
    public String getInteresttypes() {
        return interesttypes;
    }
    public void setInteresttypes(String interesttypes) {
        this.interesttypes = interesttypes;
    }
    public void print() {
        System.out.println("学号:" + id + "姓名:" + name + "性别:" + sex + "兴趣编号"
                + interestId + "兴趣类型" + interesttypes);
    }

    public void modify(String id2, String name2, String sex2,
            String interestId2, String interesttypes2) {
        this.id = id2;
        this.name = name2;
        this.sex = sex2;
        this.interestId = interestId2;
        this.interesttypes = interesttypes2;

    }
   
   
}

----------------解决方案--------------------------------------------------------
怎么没有人啊
----------------解决方案--------------------------------------------------------
java,还没学,不懂
----------------解决方案--------------------------------------------------------
等有时间了
----------------解决方案--------------------------------------------------------
这个好像是比赛题??
----------------解决方案--------------------------------------------------------
  相关解决方案