Question

How can I access the CD Rom drive (in my case, F:) from Java? I don't mind platform specific code. I am using Windows 8. I have the following code but get AccessDenied.

    public static void main(String args[]) throws IOException {     
        File cd = new File( "f:\\lang" );
        System.out.println(cd.canRead());
        RandomAccessFile rawAccess = new RandomAccessFile( cd, "r" );

        rawAccess.close();
   }

The 3 trues are checking for cd.canRead, cd.canWrite, cd.canExecute.

   true
   true
   true
   Exception in thread "main" java.io.FileNotFoundException: f:\lang (Access is denied) at java.io.RandomAccessFile.open(Native Method)
   at java.io.RandomAccessFile.<init>(Unknown Source) at myapp.main(myapp.java:16)
Was it helpful?

Solution 2

I see my error now. I'm trying to use the Java File object when what I really want is raw data from the disc. I was giving a directory and trying to open it like a file causing the error seen in the original post. It worked once I changed the path to a specific file.

I will create a new question that is more clear about what I want. Thank you.

OTHER TIPS

RandomAccessFile provides access to Files not Directories.

The FileNotFound is thrown, because there is no file, just a directory.

http://docs.oracle.com/javase/6/docs/api/java/io/RandomAccessFile.html#RandomAccessFile(java.io.File, java.lang.String)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top