java写一个程序,实现从文件中读出文件内容,并将其打印在屏幕当中,并标注上行号。 
最好具体点,虽然这类题很多,但本人这方面实在练习太少,还请高手多多指导,给出明确答案。谢谢!!

解决方案 »

  1.   


    File file = new File(pathStr);
    BufferedReader reader = null;
    try {
    reader = new BufferedReader(new FileReader(file));
    String tempString = null;
    int lineNo = 1;
    while ((tempString = reader.readLine()) != null) {
    System.out.println(lineNo + ":" + tempString);
                                    lineNo = lineNo + 1;
    }
    } catch (IOException e) {
    // 例外处理
    } finally {
    try {
    if (null != reader){
    reader.close();
    }
    } catch (IOException e1) {
    // 例外处理
    }
    }不知道能否满足LZ的要求