Scanner is never closed

前端 未结 4 1780
渐次进展
渐次进展 2020-12-01 10:34

I\'m working on a game and I came across a little problem with my scanner. I\'m getting a resource leak scanner never closed.

But I thought my scanner was working be

4条回答
  •  囚心锁ツ
    2020-12-01 11:18

    Here is some better usage of java for scanner

    try(Scanner sc = new Scanner(System.in)) {
    
        //Use sc as you need
    
    } catch (Exception e) {
    
            //  handle exception
    
    }
    

提交回复
热议问题