PrintStream Only Printing out the Last Line of Input File

后端 未结 2 1746
星月不相逢
星月不相逢 2021-01-29 07:34

I have this code

public class program {
    public static void main(String[] args) {
        try {
            String filePath = (args[0]);
            String st         


        
2条回答
  •  北海茫月
    2021-01-29 08:26

    Don't create a new PrintStream in each loop. Instead create the PrintStream prior to the while loop:

    PrintStream out = new PrintStream( ... );
    while ((strLine = br.readLine()) != null) {
      out.print(strLine);
    }            
    

提交回复
热议问题