如何从 BeanShell 加载文件?
How to Load files from BeanShell?
如何iterate the directory contents and put each file变成List
或其他collection?
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$
到 bulk convert 格式(尽管 BeanShell
可能有点矫枉过正)。
BeanShell
会不会Load
这个文件? 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 );
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);
如何iterate the directory contents and put each file变成List
或其他collection?
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$
到 bulk convert 格式(尽管 BeanShell
可能有点矫枉过正)。
BeanShell
会不会Load
这个文件? 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 );
无法用
假设您必须避免使用 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);