不读特定文件

时间:2013-11-20 05:35:29

标签: java

我的文件名为Invictus.txt,内容为

Invictus
William Ernest Henley (1849–1903).

Out of the night that covers me,
Black as the pit from pole to pole,
I thank whatever gods may be
For my unconquerable soul.

In the fell clutch of circumstance
I have not winced nor cried aloud.
Under the bludgeonings of chance
My head is bloody, but unbowed.

Beyond this place of wrath and tears
Looms but the Horror of the shade,
And yet the menace of the years
Finds and shall find me unafraid.

It matters not how strait the gate,
How charged with punishments the scroll,
I am the master of my fate:
I am the captain of my soul

我正在使用

Scanner input = new Scanner(new File(fileName));

但是

input.hasNext 

返回null, 它与其他文件一起正常工作!!!

1 个答案:

答案 0 :(得分:0)

input.hasnext错误,请使用input.hasNext

  

public boolean hasNext()

     

如果此扫描仪具有另一个,则返回true   令牌输入。此方法可能在等待输入时阻塞   扫描。扫描仪不会超过任何输入。

您的文件可能是empty。这就是为什么你得到null