简体   繁体   English

适用于Windows和OS X的Java应用程序的可行性

[英]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. 我正在编写此应用程序,它需要我用Java列出目录及其子目录中的所有文件,并删除所有mp3文件。

As of now I am using Apache Commons libraries and looking for mp3 files like this 截至目前,我正在使用Apache Commons库,并正在寻找这样的mp3文件

mp3Files = (List<File>) FileUtils.listFiles(path ,new SuffixFileFilter(".mp3"), TrueFileFilter.INSTANCE);

Now the main directory URL i am taking from the user. 现在,我从用户那里获取主目录URL。

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? 所以我想知道的是,代码对于Windows和os x是否会以相同的方式工作? will it delete all the mp3 files irrespective of the OS or will the different file structure cause any issue? 它将删除所有mp3文件而不考虑操作系统,还是将不同的文件结构引起任何问题?

Java is OS agnostic, so you should be fine. Java与操作系统无关,因此您应该没事。 But that doesn't mean that your Java code is also OS agnostic. 但这并不意味着您的Java代码也与操作系统无关。 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. 这意味着您不应该对分隔符进行硬编码,而应使用File.separator

Also, using File and not making any assumptions about your environment will help you out as well. 同样,使用File而不对环境做任何假设也将对您有所帮助。

edit : Yes, you should be fine using FileUtils and searching for MP3 files in that manner. 编辑 :是的,使用FileUtils并以这种方式搜索MP3文件应该没问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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