Using BufferedReader.readLine() in a while loop properly

后端 未结 7 1652
无人共我
无人共我 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:17

    In case if you are still stumbling over this question. Nowadays things look nicer with Java 8:

    try {
      Files.lines(Paths.get(targetsFile)).forEach(
        s -> {
          System.out.println(s);
          // do more stuff with s
        }
      );
    } catch (IOException exc) {
      exc.printStackTrace();
    }
    

提交回复
热议问题