Using BufferedReader.readLine() in a while loop properly

后端 未结 7 1632
无人共我
无人共我 2020-11-27 19:35

So I\'m having an issue reading a text file into my program. Here is the code:

     try{
        InputStream fis=new FileInputStream(targetsFile);
        Bu         


        
7条回答
  •  再見小時候
    2020-11-27 20:20

    In addition to the answer given by @ramin, if you already have BufferedReader or InputStream, it's possible to iterate through lines like this:

    reader.lines().forEach(line -> {
        //...
    });
    

    or if you need to process it with given order:

    reader.lines().forEachOrdered(line -> {
        //...
    });
    

提交回复
热议问题