groovy script Error

拥有回忆 提交于 2019-12-11 07:12:46

问题


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


回答1:


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


来源:https://stackoverflow.com/questions/25285715/groovy-script-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!