Reputation: 4340
I am writing this app which requires me to list all the Files in a directory and its subdirectories and delete all mp3 file, in Java.
As of now I am using Apache Commons
libraries and looking for mp3 files like this
mp3Files = (List<File>) FileUtils.listFiles(path ,new SuffixFileFilter(".mp3"), TrueFileFilter.INSTANCE);
Now the main directory URL i am taking from the user.
Rest of the work my app does.
So what I was wondering is, will the code work the same way for both windows and os x? will it delete all the mp3 files irrespective of the OS or will the different file structure cause any issue?
Upvotes: 0
Views: 78
Reputation: 95588
Java is OS agnostic, so you should be fine. But that doesn't mean that your Java code is also OS agnostic. There should be some OS-specific things that you need to take into consideration like separators. This means that you shouldn't hard-code the separator, but use File.separator
instead.
Also, using File
and not making any assumptions about your environment will help you out as well.
edit: Yes, you should be fine using FileUtils
and searching for MP3 files in that manner.
Upvotes: 3