java Runtime.getRunTime()。exec&通配符? [英] java Runtime.getRunTime().exec & wildcards?

查看:431
本文介绍了java Runtime.getRunTime()。exec&通配符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过使用

Process p = Runtime.getRuntime().exec();

它工作正常,只要我不使用通配符,即这样工作:

it works fine as long as i do not use wildcards, i.e. this works:

Process p = Runtime.getRuntime().exec("/bin/rm -f specificJunkFile.java");

,而以下内容会抛回没有此类文件或目录:

while the following throws back "No such file or directory":

Process p = Runtime.getRuntime().exec("/bin/rm -f *.java");

我应该能够做所有的好东西这里,对吗?

i should be able to do all the nice things as outlined here, right?

推荐答案

p>我建议你让Java为你做这个?

Might I suggest that you let Java do this for you?


  • 使用file.listFiles()获取文件列表

  • 使用file.getName()包含(string)来过滤需要的

  • 在执行file.delete
  • Use file.listFiles() to get the list of files
  • Use file.getName().contains(string) to filter them if needed
  • iterate over the array performing file.delete()

优点:提高可移植性,节省exec()的成本

Advantage: improved portability, saves the cost of an exec()

这篇关于java Runtime.getRunTime()。exec&通配符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆