做了,,一下午了,,,可能是对io流使用的很不熟练,,尝试过好几种思路还没实现,,
希望大神,,有时间给个思路清晰的,答案,,,谢谢谢鞋了。

解决方案 »

  1.   

    说说你遇到的难点 写入文件应该很简单吧 工具类很多  数组的数据可以循环调用这个方法  只要注意追加覆盖的区别
    如下:file是文件路径 content是内容
    public static void write(String file, String conent) throws IOException {
            File file2 = new File(file);
            if (!file2.exists()) {
                file2.createNewFile();
            }
            BufferedWriter out = null;
            try {
                out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file, true)));
                out.write(conent + "\r\n");
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                try {
                    out.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
      

  2.   

    import java.io.*;/**
     * 数据源文件信息:
     * 张三;男;1529366;
     * 小米;女;13;
     * lili;女;11111;
     * <p>
     * 数据源要求:以';'分割属性
     */
    public class IO {    //数据源条数
        static final int COUNT = 3;
        //保存从文件中读取到的信息;
        static String[][] phoneArrs = new String[COUNT][];    //创建数据源文件对象(从该文件对象读取信息)
        static File readFiel = new File("src/phoneData.txt");
        //创建输出文件对象(保存输出的信息)
        static File writeFile = new File("src/phoneBook.txt");    //输出字节流
        static OutputStream out;
        //输入缓冲流
        static BufferedReader br;    /**
         * @Author: hyh
         * 读取文件信息
         */
        static void readBook() {
            try {
                //实例化输入流对象
                br = new BufferedReader(new FileReader(readFiel));
                //用于保存读取到的字符串(readLine每次读取一行)
                String str;
                //循环读取文件,直到文件末尾
                for (int i = 0; i < COUNT && (str = br.readLine()) != null; i++) {
                    String[] strings;
                    //按';'分割字符串,得到一个新的字符串数组
                    strings = str.split(";");
                    //把得到的字符串数组存放到phoneBook中
                    phoneArrs[i] = strings;
                }
                //关闭流
                br.close();
                System.out.println("读取完成");
            } catch (IOException e) {
                e.printStackTrace();
            }
        }    /**
         * @Author: hyh
         * 把数组信息写到文件中
         */
        static void writeBook() {
            String[] temp;  //表示一条联系人信息
            try {
                //实例化输出流对象(追加信息)
                out = new FileOutputStream(writeFile, true);            for (int i = 0; i < phoneArrs.length; i++) {
                    temp = phoneArrs[i];
                    //写入一条信息
                    for (int j = 0; j < temp.length; j++) {
                        out.write(temp[j].getBytes());
                        //添加符号
                        out.write(';');
                    }
                    //每条信息写入完成后换行
                    out.write('\n');
                }
                //关闭流
                out.flush();
                out.close();
                System.out.println("写入完成");
            } catch (IOException e) {
                e.printStackTrace();
            }
        }    public static void main(String[] args) {
            readBook();
            //读取完成后,对数据进行修改
            phoneArrs[1][1] = "修改的数据111";
            //修改完成,写入文件
            writeBook();
        }}