简体   繁体   中英

feasibility of java app for windows and os x

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM