如何从服务器读取文本文件。下面是我的文件结构如何使用scala从服务器读取文本文件
阶
主 SRC Scala类
properties
readme.txt
下面是我的代码
文件路径= “/properties/readme.txt”
val textfilecontent: String= scala.io.Source.fromFile(filepath).getLines.mkString
我收到文件不是基金会d例外。在此先感谢
如何从服务器读取文本文件。下面是我的文件结构如何使用scala从服务器读取文本文件
阶
主 SRC Scala类
properties
readme.txt
下面是我的代码
文件路径= “/properties/readme.txt”
val textfilecontent: String= scala.io.Source.fromFile(filepath).getLines.mkString
我收到文件不是基金会d例外。在此先感谢
移动属性文件夹到你的资源目录像下面
resources
properties
readme.txt
现在你阅读使用下面的代码段的文件。
scala.io.Source.fromFile(this.getClass.getResource("/properties/readme.txt").getFile).getLines.mkString
非常感谢。它工作正常。无需移动到资源目录。我使用以下代码: val resourcesPath = getClass.getResource(filePath) val stopWord = scala.io.Source.fromFile(resourcesPath.getPath).mkString –
以/
开头的路径是绝对路径。您应该提供绝对路径,或者如果这是正确的相对路径,请删除/
。
是属性在您的项目目录? –
是的。我的项目文件夹的一部分.. –