代码如下:
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(
                new FileInputStream("hd1.txt")));
        line = reader.readLine();
        System.out.println(line);
        if(line == null)
         return "文件为空!";
        //else {
        if(line != null){
         StringTokenizer stringTokenizer = new StringTokenizer(line,"\u5639\u563b");
    while(stringTokenizer.hasMoreTokens()){
     String phone = stringTokenizer.nextToken();
     String[] phoneInfo = phone.split(",");
     String tempNumber = phoneInfo[1].substring(1,phoneInfo[1].length()-1);
     //System.out.println(phone);
     if(tempNumber.equals(phoneNumber.substring(0,7))){
     cityName = phoneInfo[0].substring(1,phoneInfo[0].length()-1);
     break;
     }
    } 
        }        
        reader.close();
} catch(IOException ioe) {
ioe.printStackTrace();
}hd1.txt文件:
"col001","col002","mobileflag","id"
"阿坝","1388248","qqt",1
"阿坝","1388249","qqt",2
"阿坝","1399040","qqt",3
"阿坝","1399041","qqt",4
"阿坝","1399042","qqt",5
为社么读取到hd1.txt文件的第一行?

解决方案 »

  1.   

    因为你只用了一次readlin啊
    line = reader.readLine();应该像这样循环读
    while  ((line  =  reader.readLine())  !=  null)
    {
    ....
    }
      

  2.   

    if(line != null){改为while(line!=null)
    才能循环读取所有行
      

  3.   

    while  ((line  =  reader.readLine())  !=  null)
    {
    ....
    }
    正解
      

  4.   

    line = reader.readLine();只读了一行呀!
    改为while(line!=null)
    才能循环读取所有行
      

  5.   

    因为你只用了一次readlin啊
    line = reader.readLine();应该像这样循环读
    while  ((line  =  reader.readLine())  !=  null)
    {
    ....
    }
      

  6.   

    9494,赶快路过,kingofworl(良辰美景虚度) 给的是正解,啦啦啦
      

  7.   

    你怎么不用read(byte[])列  这样你想读多少都么的问题  呵呵
      

  8.   

    各位看看这么说是不是通俗一点,readLine()确实是每次只读出一行,所以你需要用一个循环来读出每一行
      

  9.   

    while  ((line  =  reader.readLine())  !=  null)
    {
    ....
    }
    正解
      

  10.   

    /**
         * Read a line of text.  A line is considered to be terminated by any one
         * of a line feed ('\n'), a carriage return ('\r'), or a carriage return
         * followed immediately by a linefeed.
         *
         * @return     A String containing the contents of the line, not including
         *             any line-termination characters, or null if the end of the
         *             stream has been reached
         *
         * @exception  IOException  If an I/O error occurs
         */