Reputation: 3822
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)
Upvotes: 0
Views: 1220
Reputation: 16060
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)
Upvotes: 2
Reputation: 3822
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.
Upvotes: 1