我把表里的记录读出来保存在文本文件中,比如说表里有username、password两个字段,有3条记录
分别是:
li,123
liu,234
wang,345
项目要求我保存在文本文件中的样式是:
li●123
liu●234
wang●345
既字段间用“●”隔开,每条记录要求换行,在写入文本文件时,换行符我用的是“\r\n”
现在我要读这个文本中的数据,恢复到数据库里,但不知道怎么读这个文本文件,怎么把文本文件中的数据按记录读,然后按字段付给变量,循环插入数据库?请大家告诉我,最好能给我断程序,万分感谢了!!!

解决方案 »

  1.   

    readline该文件,然后以●分割每行(用charat也可以),应该不难.
    分多点的话我就帮你写了
      

  2.   

    以下一个读文件的例程,希望对楼主有帮助.
    /* Readfile.java读取文件的内容,并将原样输出至屏幕上使用方法:java Readfile 文件名*/import java.io.*;public class Readfile{public static void main(String[] args){byte[] buff = new byte[1024];boolean cont = true;FileInputStream infile = null;// 生成对象infile 准备读取文件try{infile = new FileInputStream(args[0]);}catch (FileNotFoundException e){System.err.println("没有找到文件");System.exit(1);}while (cont){try{int n = infile.read(buff); // 从文件读取数据System.out.write(buff, 0, n); // 写入System.out中}catch (Exception e){cont = false;} }try{infile.close();}catch (IOException e){System.err.println("文件错误");System.exit(1);}}}