1

How would i make a java program find and delete all the files in my computer that have the extension: .jar?

I have the command:

find . -type f -name "*.jar" -exec rm -i {} \;

I know how to execute commands, but i don't know how to tell it to execute this command.

Shifty16
  • 29
  • 6

2 Answers2

1

Simply, you CAN't delete ALL .jar files on computer. Because your java program needs JVM to run and since jvm uses jar files present under lib of JRE insallation. And in order to run your program you need lib jar files.

Although, you can give it a try with example from mkyong.

http://www.mkyong.com/java/how-to-find-files-with-certain-extension-only/

Dark Knight
  • 8,218
  • 4
  • 39
  • 58
0

You can use a FilenameFilter to see if files match your pattern. http://docs.oracle.com/javase/7/docs/api/java/io/FilenameFilter.html

Once you have found a file you want to delete, use File.delete() to actually delete it. http://docs.oracle.com/javase/1.4.2/docs/api/java/io/File.html#delete%28%29

Colin D
  • 5,641
  • 1
  • 23
  • 35