I have the following code:
InputStream in = this.getClass().getClassLoader().getResourceAsStream("test.groovy");
I need to pass this resource to the method called parse
which takes File
as param, so doing so fails:
new GroovyShell().parse(new FileInputStream(in));
How I can convert FileInputStream
to File
in java?
您实际上可以使用: GroovyShell #parse(Reader)方法:
Script result = new GroovyShell().parse(new InputStreamReader(in));
use this :
try {
URL url = this.getClass().getClassLoader().getResource("test.groovy");
File file = new File(url.toURI());
new Shell().parse(file);
} catch(...){...}
if you know exact path to "test.groovy", do this:
new Shell().parse(new File("path/to/test.groovy"));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.