groovy脚本错误 [英] groovy script Error

查看:261
本文介绍了groovy脚本错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新手常规。在命令提示符下(我没有使用任何IDE),我输入以下内容:(请不要使用环境变量设置问题)

  groovy -n -eprintln line.toLong()data.txt 

错误:

 抓取:java.io.IOException:无效参数
java.io.IOException:无效参数

data.txt位于该目录中(使用TAB键进行验证)




不知道为什么它抛出错误???? b
$ b [data.txt包含原始数据在以下格式中:

1 1

2

3



4

解决方案

Groovy 2.3.6和Java 1.7.0_60在Linux上没有问题:

  $ echo -e1 \\\
2\\ \\ n \ 3 \\\
\4> data.txt
$ groovy -n -eprintln line.toLong()data.txt
1
2
3
4

使用不存在的文件:

  $ groovy -n -eprintln line.toLong()bogus.txt 
Caught:java.io.FileNotFoundException:bogus.txt
java.io.FileNotFoundException:bogus.txt

使用非数字数据:

  $ echo -ea\\\
b\\\
c\\\
d> data.txt
$ groovy -n -eprintln line.toLong()data.txt
Caught:java.lang.NumberFormatException:对于输入字符串:a
java.lang .NumberFormatException:对于输入字符串:a
at script_from_command_line.run(script_from_command_line:1)

它甚至与CR / LF EOL一起工作:

  $ echo -e1 \r\\\
2\ r \\\
3\r\\\
4\r> data.txt
$ groovy -n -eprintln line.toLong()data.txt
1
2
3
4


I am newbie to groovy. In command prompt (I am not using any IDE), I typed following : (No Problem with environment variables settings please)

groovy -n -e "println line.toLong()" data.txt

Error :

Caught: java.io.IOException: Invalid argument
java.io.IOException: Invalid argument

data.txt is there in that directory (verified using TAB key)


Not sure why its throwing Error ????

[data.txt contains raw data in following format]

1

2

3

4

解决方案

I tried to duplicate the problem with Groovy 2.3.6 and Java 1.7.0_60 on Linux and had no issue:

$ echo -e "1\n2\n\3\n\4" > data.txt
$ groovy -n -e "println line.toLong()" data.txt
1
2
3
4

With a non-existing file:

$ groovy -n -e "println line.toLong()" bogus.txt
Caught: java.io.FileNotFoundException: bogus.txt
java.io.FileNotFoundException: bogus.txt

With non-numeric data:

$ echo -e "a\nb\nc\nd" > data.txt
$ groovy -n -e "println line.toLong()" data.txt
Caught: java.lang.NumberFormatException: For input string: "a"
java.lang.NumberFormatException: For input string: "a"
        at script_from_command_line.run(script_from_command_line:1)

And it even worked with CR/LF EOL:

$ echo -e "1\r\n2\r\n3\r\n4\r" > data.txt
$ groovy -n -e "println line.toLong()" data.txt
1
2
3
4

这篇关于groovy脚本错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆