Scanner No Line Found Exception

亡梦爱人 提交于 2019-11-29 18:07:42

new File("restrictions.txt") will look for the file in the "Start dir" of your app - if you're using Eclipse, it's probably the root of your project.

To open the file next to your class, you can use the Scanner constructor which accepts an InputStream that you get by

YourClass.class.getResourceAsStream("restrictions.txt")
divya

You should use if(in.hasNextLine()) before calling in.nextLine(). Otherwise for last line it will thrown Line not found exception.

Javadoc for Scanner

Do you need to specify a line ending so it knows what a line is?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!