a1 001 北京
a2 002 北京
a3 003 北京
a4 004 北京
a5 005 北京
a6 006 北京
a7 007 北京从文本中读取文件数据。我已经会了。可是不会如果截取这三列,存入mysql里。谢谢大家的帮助

解决方案 »

  1.   

    1.用BufferedReader类 的readLine()读出一行2.用.split(" ")分割字符串.3.传成相应类型数据4.写入数据库
      

  2.   

    你以行一行的读,再把每一行使用StringTokenizer按照空格分开,只取前三个就可以了
      

  3.   

    a1 001 北京 
    a1 001 北京 
    a1 001 北京 
    a1 001 北京 
    a1 001 北京 
    a1 001 北京 
    a1 001 北京 截取之后是这样的以前没用过IO。谢谢你们了。。
      

  4.   

    代码是这样的。。public class Test_1 
    { /**
     * 
     * Test类主函数
     * 
     * @param args
     * @throws IO异常
     */
    public String[] ss = new String[200]; 
    public static void main(String[] args) throws IOException 
    {
    String path = "d:\\test.txt";
    Test_1 t = new Test_1();
    if (t.isExist(path)) {
    if (t.isEmpty(path)) {
    System.out.println("success!");
    System.out.println();
    t.getValue(path);
    } else {
    System.out.println("false!");
    }
    } else {
    System.out.println("false!");
    }
    }

    /**
     * 
     * 判断文件是否存在
     * 
     * @param file 文件名
     * @return 文件是否存在 
     * true - 文件存在 
     * false - 文件不存在
     */
    boolean isExist(String file) 
    {
    File f = new File(file);
    if (f.exists()) {
    System.out.println("File is Exist!");
    return true;
    } else {
    System.out.println("File isn't Exist!");
    return false;
    }
    }
    /**
     * 
     * 判断文件是否为空
     * 
     * @param file 文件名
     * @return 文件是否为空
     * true - 文件为空 
     * false - 文件不为空
     * @throws IO异常
     */
    boolean isEmpty(String file) throws IOException {
    FileReader fr = new FileReader(file);
    if (fr.read() == -1) {
    System.out.println("File is Empty!");
    return false;
    } else {
    System.out.println("File isn't Empty!");
    return true;
    }
    }
    /**
     * 
     * 读取文件
     * 
     * @param file 文件名
     * @throws IO异常
     */
    void getValue(String file) throws IOException {
    FileReader fr;
    fr = new FileReader(file);
    BufferedReader br = new BufferedReader(fr);
    String line = "";
    line = br.readLine();
    ss = line.split(" ");   
    while (line !=null)
    {
    for(int i=0;i<ss.length;i++)
    {
    System.out.print(ss[i]+" ");
    }
    System.out.println();
    line = br.readLine();
    }


    // while (line != null) {
    // String lineNew = "";
    // lineNew = line;
    // System.out.println(lineNew);
    // line = br.readLine();
    // }
    }