码迷,mamicode.com
首页 > 其他好文 > 详细

[原创]Scala学习:编写Scala脚本

时间:2016-05-20 23:43:32      阅读:197      评论:0      收藏:0      [点我收藏+]

标签:

scala支持脚本

  1)在/opt/scala-script下创建一个文件hello.scala 编辑内容如下:

   $ hello ,this is the first scala script

  2)运行脚本

    技术分享

 

scala脚本的命令行参数保存在名为args的scala数组中。scala里,数组以0开始,可以通过在括号里指定索引值来访问数组元素。scala里数组 args 的第一个元素是:args(0),而不是像Java那样的:args[0]。现在,把以下内容写到新文件:

 HelloWithArgs.scala中测试一下:

//向第一个参数打问好    
 println("hello :"+ args(0))

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

root@scala:/opt/scala-script#scala hello.scala
java.net.UnknownHostException: scala: scala: unknown error
at java.net.InetAddress.getLocalHost(InetAddress.java:1505)
at scala.tools.nsc.io.Socket$.localhost(Socket.scala:28)
at scala.tools.nsc.CompileSocket.getsock$1(CompileSocket.scala:175)
at scala.tools.nsc.CompileSocket.getOrCreateSocket(CompileSocket.scala:190)
at scala.tools.nsc.ScriptRunner.compileWithDaemon(ScriptRunner.scala:70)
at scala.tools.nsc.ScriptRunner.scala$tools$nsc$ScriptRunner$$compile$1(ScriptRunner.scala:113)
at scala.tools.nsc.ScriptRunner$$anonfun$withCompiledScript$1.apply$mcZ$sp(ScriptRunner.scala:161)
at scala.tools.nsc.ScriptRunner$$anonfun$withCompiledScript$1.apply(ScriptRunner.scala:129)
at scala.tools.nsc.ScriptRunner$$anonfun$withCompiledScript$1.apply(ScriptRunner.scala:129)
at scala.tools.nsc.util.package$.trackingThreads(package.scala:43)
at scala.tools.nsc.util.package$.waitingForThreads(package.scala:27)
at scala.tools.nsc.ScriptRunner.withCompiledScript(ScriptRunner.scala:128)
at scala.tools.nsc.ScriptRunner.runScript(ScriptRunner.scala:192)
at scala.tools.nsc.ScriptRunner.runScriptAndCatch(ScriptRunner.scala:205)
at scala.tools.nsc.MainGenericRunner.runTarget$1(MainGenericRunner.scala:67)
at scala.tools.nsc.MainGenericRunner.run$1(MainGenericRunner.scala:87)
at scala.tools.nsc.MainGenericRunner.process(MainGenericRunner.scala:98)
at scala.tools.nsc.MainGenericRunner$.main(MainGenericRunner.scala:103)
at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala)
Caused by: java.net.UnknownHostException: scala: unknown error
at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
at java.net.InetAddress$2.lookupAllHostAddr(InetAddress.java:928)
at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1323)
at java.net.InetAddress.getLocalHost(InetAddress.java:1500)
... 18 more

[原创]Scala学习:编写Scala脚本

标签:

原文地址:http://www.cnblogs.com/jasonHome/p/5510682.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!