I Am Not Getting the Result I Expect Using readLine() in Java

前端 未结 3 857
一向
一向 2021-01-05 21:20

I am using the code snippet below, however it\'s not working quite as I understand it should.

public static void main(String[] args) {
    BufferedReader         


        
3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-05 22:07

    There's a nice apache commons lang library which has a good api for common :) actions. You could use statically import StringUtils and use its method isNotEmpty(String ) to get:

    while(isNotEmpty(line)) {
        System.out.println(line);
        line = br.readLine();
    }
    

    It might be useful someday:) There are also other useful classes in this lib.

提交回复
热议问题