Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/jenkins/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用scala从服务器读取文本文件_Scala - Fatal编程技术网

如何使用scala从服务器读取文本文件

如何使用scala从服务器读取文本文件,scala,Scala,如何从服务器读取文本文件。下面是我的文件结构 斯卡拉 主要 src scala类 properties readme.txt 下面是我的代码 filepath=“/properties/readme.txt” 我正在获取文件未找到异常。提前感谢以/开头的路径是绝对路径。您应该提供一个绝对路径,或者删除/,如果这是正确的相对路径。将属性文件夹移动到资源目录,如下所示 resources properties readme.txt 现在,您可以使用下面的代码段读取该文件 sca

如何从服务器读取文本文件。下面是我的文件结构

斯卡拉

主要 src scala类

properties
  readme.txt
下面是我的代码

filepath=“/properties/readme.txt”


我正在获取文件未找到异常。提前感谢

/
开头的路径是绝对路径。您应该提供一个绝对路径,或者删除
/
,如果这是正确的相对路径。

将属性文件夹移动到资源目录,如下所示

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
scala.io.Source.fromFile(this.getClass.getResource("/properties/readme.txt").getFile).getLines.mkString