我采用一下方式读取文件,在我开发(windows2000)上没有问题,程序运行正常,然而在Redhat AS4 linux 上运行却读取
40多后就不能读取了,程序就停止在注释1的行上(其实程序没有停止,进程还在运行,只是不往下运行了),真不知道为什么,向各位高手求救!!!
我的程序;
String strBuf = null;
        InputStreamReader reader = null;
        FileInputStream input = null;
        BufferedReader in = null;        try {
            input = new FileInputStream(file);
            reader = new InputStreamReader(input, Constants.FILE_ENCODING);
            in = new BufferedReader(reader);            while ((strBuf = in.readLine()) != null) {      // 1                if (zf_pattern.matcher(strBuf).matches()) {
//                    logger.warn("find a validate code:" + strBuf);
                    synchBussinessInfoData = new SynchBussinessInfoData();
                    st = new StringTokenizer(strBuf);
                    //记录到synchBussinessInfoData类
                       synchBussinessInfoData.setSecondID(st.nextToken(token).trim());
                    synchBussinessInfoData.setSecondName(st.nextToken(token).trim());
                    synchBussinessInfoData.setFirstID(st.nextToken(token).trim());
                    synchBussinessInfoData.setFirstName(st.nextToken(token).trim());
                    list.add(synchBussinessInfoData);
                } else {
                    logger.error("not find a validate code.");
                    logger.error("ERROR:"+strBuf);
                    list.clear();
                    break;
                }
            }

解决方案 »

  1.   

    代码贴的不全啊,你怎么捕获异常的?
    "读取40多后就不能读取了?“
    你可以System.out一下看看读到40个数据的结果是什么?
    文件里下个没读出的又是什么?你就这么一说,没法帮你.
      

  2.   

    看不出来你的程序有什么问题,我有一个怀疑是你的输入文件有问题,windows和linux下文件的换行符号是不一样的。首先你在linux下使用dos2unix将你的输入文件转换一下再试试看。
      

  3.   

    读到的40条数据的结果是正常的,后来就停到readLine()这行了,在文件换行符上,readLine()可分辨的换行符有;\n,\r,\n\r,应该没有问题的,用UE打开文件,还是一行行的。为什么流读到一半就不能读了??