开发者

Differentiate CD-Drive and Hard Disk-Drive in Java

How to differentiate CD-Drive and Hard Di开发者_开发技巧sk-Drive in Java?


Here is a solution I found using VBScript. Native Java does not distinguish between CD-Drive and Normal drives, it just files and dirs.

But this solution will only work on Windows.

Another solution for Windows is JNA

So, for Linux based machines, you can call a linux command from your Java code. Call a bash script.


I don't think that you can do this with complete certainty, in pure Java.

Why should you care? What you probably need to do is to distinguish between files or directories that you can write to and those that you cannot write to. The java.io.File class has methods to do that. Alternatively, if you know the (UNIX) mount point or (Windows) drive that is conventionally used for mounting CDs on your machine, you could make the distinction based on absolute pathnames. Once again, File will give you that.


Probably not a very good solution but when I use the following code on Windows:

FileSystemView fsv = FileSystemView.getFileSystemView();
System.out.println(fsv.getSystemDisplayName( new File("c:\\") ) );
System.out.println(fsv.getSystemDisplayName( new File("d:\\") ) );

I get the following output:

Local Disk (C:)
Audio CD (D:)

So maybe there are standard display names you can check for?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜