Using BufferedReader.readLine() in a while loop properly

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

    also very comprehensive...

    try{
        InputStream fis=new FileInputStream(targetsFile);
        BufferedReader br=new BufferedReader(new InputStreamReader(fis));
    
        for (String line = br.readLine(); line != null; line = br.readLine()) {
           System.out.println(line);
        }
    
        br.close();
    }
    catch(Exception e){
        System.err.println("Error: Target File Cannot Be Read");
    }
    

提交回复
热议问题