How can I detect if there is a floppy in the floppy drive using Java?

Luigi Viggiano

I've seen lot of very well written Java application, that does not deal very well with the floppy problems. I found that also zip, tapes drives, and other removable mass storages get same problems. For CD-ROMs, if no cd is available it just seems as an empty filesystem, and no system messages are shown if the drive is not ready. Check this code:


      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");

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 on floppy doesn't exists
file on cd doesn't exists
I believe that this behaviour can change on different implementations of JVMs.

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.

0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact