If you want to read file from src/main/resources
directory you should use Source.fromResource
method, so try this:
(如果要从src/main/resources
目录读取文件,则应使用Source.fromResource
方法,因此请尝试以下操作:)
Source.fromResource("sample.txt")(Codec.UTF8)
Update
(更新资料)
In your case you have to use either Source.fromFile("src/main/resources/sample.txt")
or Source.fromFile("sample.txt")
if you put your file in root project directory
(如果您将文件放在根项目目录中,则必须使用Source.fromFile("src/main/resources/sample.txt")
或Source.fromFile("sample.txt")
)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…