Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/18.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
File scala/play-从上载的文件创建文件对象_File_Scala_Playframework_Upload - Fatal编程技术网

File scala/play-从上载的文件创建文件对象

File scala/play-从上载的文件创建文件对象,file,scala,playframework,upload,File,Scala,Playframework,Upload,我使用的是scala playframework。我正在上传一个文件。在服务器端,我正在成功接收文件。我想从中创建一个文件对象。怎么做 这是我到目前为止编写的代码 request.body.file("dataFile").map( currentFile => { // How to make a FILE object from currentFile //Something like //val file: File = new Fil

我使用的是scala playframework。我正在上传一个文件。在服务器端,我正在成功接收文件。我想从中创建一个文件对象。怎么做

这是我到目前为止编写的代码

  request.body.file("dataFile").map(
    currentFile => {
      // How to make a FILE object from currentFile
      //Something like
      //val file: File = new File(currentFile)
    }
  )
可能吗?如果是的话,那怎么办?提前谢谢

根据需要,它应该是这样工作的:

  request.body.file("dataFile").map(
    currentFile => {
      // How to make a FILE object from currentFile
      import java.io.File
      val filename = currentFile.filename
      val contentType = currentFile.contentType
      val myFile = new File(s"/tmp/somepath/$filename")
      currentFile.ref.moveTo(myFile)
      //now "myFile" is an object of type "File".
    }
  )

谢谢你的回答。什么是“/tmp/somepath/”?我可以写“somepath”吗?还是应该是特定于应用程序的?只需输入要存储文件的路径即可。它可以是绝对的(即
c:\\myFiles\\test.txt
/myFiles/test.txt
,具体取决于您的操作系统),也可以是相对的(相对于您的项目目录)。如果您使用
somepath.ext
它将在项目根目录中创建一个文件。我刚才看到点前面有一些额外的空格。您可能需要删除它们。