How can I detect if there is a floppy in the floppy drive using Java?
On my PC, the check on the floppy shows the system message asking to insert floppy; on the CD this not happens, and the output on my system (Sun JDK 1.3.1) is:
File fileFloppy = new File("A:/dummy.txt"); File fileCDROM = new File("E:/dummy.txt"); if (fileFloppy.exists()) System.out.println("file on floppy exists"); else System.out.println("file on floppy doesn't exists"); if (fileCDROM.exists()) System.out.println("file on cd exists"); else System.out.println("file on cd doesn't exists");
I believe that this behaviour can change on different implementations of JVMs.
file on floppy doesn't exists file on cd doesn't exists
In Unix, a removable disk can be mounted or not, but no problem arise because the OS deals with those devices differently; with Windows the operating system shows the message dialog saying that the disk is not ready. This cannot be handled or trapped by a Java Application, because the OS comes first and handle it its own. The only way, is to write a low level code to check if the disk is present and interface it with Java thru JNI.
In other words, to the best of my knowledge, you cannot do anything to manage the problem with Java code, it is a platform dependent problem / requires JNI.