Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/308.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何从BeanShell加载文件?_Java_File_Scripting_Beanshell_System Administration - Fatal编程技术网

Java 如何从BeanShell加载文件?

Java 如何从BeanShell加载文件?,java,file,scripting,beanshell,system-administration,Java,File,Scripting,Beanshell,System Administration,我如何进入列表或其他集合 thufir@dur:~/beanshell$ thufir@dur:~/beanshell$ bsh list_ebooks.bsh ebook files to iterate rw_ Dec 19 368225 1 - foundation - isaac asimov.epub rw_ Dec 19 395042 2 - foundation and empire - isaac asimov.epub rw_ Dec 19 374631 3 -

我如何进入
列表
或其他集合

thufir@dur:~/beanshell$ 
thufir@dur:~/beanshell$ bsh list_ebooks.bsh 
ebook files to iterate
rw_ Dec 19   368225 1 - foundation - isaac asimov.epub
rw_ Dec 19   395042 2 - foundation and empire - isaac asimov.epub
rw_ Dec 19   374631 3 - second foundation -  isaac asimov.epub
rw_ Dec 19  2084565 4 - foundation's edge -  isaac asimov.epub
rw_ Dec 19  2125777 5 - foundation and earth -  isaac asimov.epub
rw_ Dec 19  2187662 6 - prelude to foundation -  isaac asimov.epub
rw_ Dec 19  2173565 7 - forward to foundation -  isaac asimov.epub
thufir@dur:~/beanshell$ 
thufir@dur:~/beanshell$ cat list_ebooks.bsh 


print("ebook files to iterate");

dir("/home/thufir/ebooks/foundation/");


thufir@dur:~/beanshell$ 
对格式的修改(尽管BeanShell可能有些过分)

BeanShell
是否将
加载该文件?委员会:

使用目录和路径BeanShell支持 用于处理文件的命令的当前工作目录。裁谈会() 命令可用于更改工作目录,pwd()可以 用于显示当前值。BeanShell当前正在运行 目录存储在变量bsh.cwd中

使用文件的所有命令都与工作目录有关, 包括:

dir()
source()
run(),
cat()
load()
save()
mv()
rm()
addClassPath()
pathToFile()可以方便地编写自己的脚本和 命令您可以使用pathToFile()命令转换相对文件 相对于当前加工的绝对文件路径 目录绝对路径未被修改

apache文件utils


无法使用。

假设您必须避免流,您可以返回到旧方法:

List result=new ArrayList();
File dir=新文件(“/tmp”);
File[]files=dir.listFiles();
如果(文件!=null){
用于(文件f:文件){
if(f.isFile()){
结果:添加(f);
}
}
}
系统输出打印项次(结果);
absfilename = pathToFile( filename );
List<File> result = new ArrayList<>();
File dir = new File("/tmp");
File[] files = dir.listFiles();
if (files != null) {
    for (File f : files) {
        if (f.isFile()) {
            result.add(f);
        }
    }
}
System.out.println(result);