gpt4 book ai didi

java - 如何从 BeanShell 加载文件?

转载 作者:行者123 更新时间:2023-12-02 10:27:03 25 4
gpt4 key购买 nike

如何将 iterate the directory contents and put each file 放入 List 或其他集合中?

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$

to bulk convert 格式(尽管 BeanShell 可能有点过头了)。

BeanShell加载 文件吗? fine manual:

Working with Dirctories and Paths BeanShell supports the notion of a current working directory for commands that work with files. The cd() command can be used to change the working directory and pwd() can be used to display the current value. The BeanShell current working directory is stored in the variable bsh.cwd.

All commands that work with files respect the working directory, including the following:

dir()
source()
run(),
cat()
load()
save()
mv()
rm()
addClassPath()

pathToFile() As a convenience for writing your own scripts and commands you can use the pathToFile() command to translate a relative file path to an absolute one relative to the current working directory. Absolute paths are unmodified.

absfilename = pathToFile( filename );

Import apache 文件实用程序?

不能用 streams 来完成。

最佳答案

假设您必须避免流,您可以回到旧的 java.io.File.listFiles()方法:

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);

关于java - 如何从 BeanShell 加载文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53869099/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com