阅读文件的问题

时间:2017-05-23 11:47:26

标签: java file arraylist hashmap

我的项目中有一个类有问题。 我试图从文件中读取所有行,但是当我打印时,它显示我少于半行。 我能做些什么呢?

1 个答案:

答案 0 :(得分:0)

在控制台中使用以下代码文件读取和打印: -

 public class ReadFileExample {

    private static final String FILENAME = "E:\\test\\filename.txt";

    public static void main(String[] args) {

        BufferedReader br = null;
        FileReader fr = null;

        try {

            fr = new FileReader(FILENAME);
            br = new BufferedReader(fr);

            String sCurrentLine;

            br = new BufferedReader(new FileReader(FILENAME));

            while ((sCurrentLine = br.readLine()) != null) {
                System.out.println(sCurrentLine);
            }

        } catch (IOException e) {

            e.printStackTrace();

        } finally {

            try {

                if (br != null)
                    br.close();

                if (fr != null)
                    fr.close();

            } catch (IOException ex) {

                ex.printStackTrace();

            }

        }

    }

}