下面的两个功能对吗?为什么老是进入catch ()里?? (源代码太长)try{
            //计算行数
            File  fis = new File ("C:\\myfile.txt");
            BufferedReader dis = new  BufferedReader(fis);
            while(dis.readLine()!=null){
                enter_count++;        
            }
            //将每一行符值给一个字符串
            fis = new FileInputStream("C:\\myfile.txt");//由于上面的dis.readLine()将文件读完了,所以要从新初始化一遍
            dis = new DataInputStream(fis);
            String s[] = new String[enter_count];
            i = 0;
            while(dis.available()!=0){
                s[i] = dis.readLine();
                s1[i]=s[i];                 
                i++;
            }
            dis.close();
   }catch(Exception e){
          System.err.println("File input error");
        }
    }
}

解决方案 »

  1.   

    上下两段分开来try/catch一下试试看...
    int enter_count = 0;
    try {
    // 计算行数
    FileInputStream fis = new FileInputStream("abc.txt");
    BufferedReader dis = new BufferedReader(new InputStreamReader(fis));
    while (dis.readLine() != null) {
    enter_count++;
    }
    System.out.println(enter_count);
    // 将每一行符值给一个字符串
    fis = new FileInputStream("abc.txt");// 由于上面的dis.readLine()将文件读完了,所以要从新初始化一遍
    DataInputStream ds = new DataInputStream(fis);
    String s[] = new String[enter_count];
    int i = 0;
    while (ds.available() != 0) {
    System.out.println(ds.readLine());
    }
    dis.close();
    } catch (Exception e) {
    e.printStackTrace();
    System.err.println("File input error");
    }

    这样是可以的...没错啊...语法错误吧?  @_@