简体   繁体   English

Scala中的Java IO

[英]Java IO in Scala

I am using Scala and am trying to use Java's IO, but I cannot seem to get it to work. 我正在使用Scala并尝试使用Java的IO,但似乎无法正常工作。 Here is the basis of what I have: 这是我所拥有的基础:

import java.io._
object test{
  def main(args: Array[String]){
   val writer = new PrintWriter(new File("test.txt"))
  }
}

When I try to compile this, I get the following: 当我尝试对此进行编译时,我得到以下信息:

Failed to execute goal net.alchim31.maven:scala-maven-plugin:3.2.2:compile (default-sbt-compile) on project SingleTableSparkScan: wrap: org.apache.commons.exec.ExecuteException: Process exited with an error: 1 (Exit value: 1) -> [Help 1] 无法在项目SingleTableSparkScan上执行目标net.alchim31.maven:scala-maven-plugin:3.2.2:compile(default-sbt-compile):包装:org.apache.commons.exec.ExecuteException:进程退出,并出现错误: 1(退出值:1)-> [帮助1]

When I remove the line that uses Java's IO, everything runs fine. 当我删除使用Java IO的行时,一切运行正常。 Any ideas? 有任何想法吗? Thanks! 谢谢!

I just tried this on http://www.tutorialspoint.com/compile_scala_online.php and the code to compiles and runs. 我刚刚在http://www.tutorialspoint.com/compile_scala_online.php上尝试了此操作,并编译并运行了代码。

There must be some kind of other problem with your set up 您的设置中肯定存在其他问题

请试试:

val writer = new PrintWriter(new File("test.txt"));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM