流程构建器打印输出而无需任何Sysout,我想将输出存储在列表中< string>
我想存储带有名称的文件夹列表,其中list_location在list ===>
ProcessBuilder processBuilder = new ProcessBuilder().directory(Paths.get(PROJECT_LOCATION)
.toFile())
.command("cmd.exe",
"/c",
"dir /b *MS;")
.inheritIO()
.redirectErrorStream(true);
Process process = processBuilder.start();
这个很多代码是按照MS结尾的文件夹的名称的,但是我想将值存储在
我尝试过的列表中=>
List<String> msList=new ArrayList<>();
BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line;
while ((line = in.readLine()) != null) {
msList.add(line);
}
process.waitFor();
System.out.println("ok! "+ msList.size());
但是列表大小的打印为0。它没有读取InputStream线路。 它不支持这种命令.....吗?
控制台输出===&gt;
CartMS
CustomerMS
PaymentMS
ProductMS
ok! 0
I want to store the list of folders with name ending with MS present at PROJECT_LOCATION in a List ===>
ProcessBuilder processBuilder = new ProcessBuilder().directory(Paths.get(PROJECT_LOCATION)
.toFile())
.command("cmd.exe",
"/c",
"dir /b *MS;")
.inheritIO()
.redirectErrorStream(true);
Process process = processBuilder.start();
this much code is prinitng the names of folders ending with MS, but i want to store the values in a List
I tried =>
List<String> msList=new ArrayList<>();
BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line;
while ((line = in.readLine()) != null) {
msList.add(line);
}
process.waitFor();
System.out.println("ok! "+ msList.size());
but the list size is printing to be 0. It is not reading the InputStream Lines.
Does it not support for these kind of commands.....?
Console output===>
CartMS
CustomerMS
PaymentMS
ProductMS
ok! 0
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当有更好的选择时,为什么要启动外部程序列出文件?
或没有流:
Why are you starting an external program to list files when there's a much better alternative?
Or without streams: