Jump to content

Is It Possible To Read Information From A Cd Using Java In Windows/linux ?


danielbrthwt

Recommended Posts

I thought that making some software that rips audio CD's and movies would be an interesting project, so to start i am trying to make something that takes the songs on a audio CD and saves to the hard rive as a WAV file, the only problem is that i cant seem to find much information on how to do this in Java and what i have found dosent, below is the code i have tried but when i run it i get access denied errors even when i run it as administrator



import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.util.Scanner;


public class learning
{
public static void main(String[] args) throws IOException
{
File cd = new File( "D:" );
RandomAccessFile rawAccess = new RandomAccessFile( cd, "r" );

byte[] content = new byte[2352];

rawAccess.readFully(content);

System.out.println(content);
}
}

[/CODE]

.

And the error i get is

[CODE]
Exception in thread "main" java.io.FileNotFoundException: D: (Access is denied)
at java.io.RandomAccessFile.open(Native Method)
at java.io.RandomAccessFile.<init>(Unknown Source)
at learning.main(learning.java:13)
[/CODE]

Is there any way to read from the CD drive in Windows/Linux using java ?

Edited by danielbrthwt
Link to comment
Share on other sites

I don't see why not, but you might need to tell Java to do something different with it, since its removable media, the mounting and reading of the data might be treated differently. I don't know much about Java, but the declaration of a new file as d: might also be part of the problem.

File cd = new File( "D:" );[/CODE]

I think if anything, you need to 1 change directory to D:, then list contents of D: and decide what file you want to copy, or, mount D: and then stream bit for bit the contents of the drive to the HDD as an ISO if ripping is what you are after vs just finding and copying one file off.

There is a tool for doing this in Java, might shed some light on it, since usually they post the source code with it too on sourceforge - http://jiic.berlios.de/ might have bits of code you would or could reuse or rewrite, or just use in general to see how its done.

By the way, CD and DVD roms, have different ways they can be written to them, like Jolient, and ISO standards, some like audio cd's that also have data partitions on them(who remembers those from back in the day, making a mucic cd that contained wallpapers and videos too), so reading from them might also need to know how to look up the redbook standard the disc was created with before you can read from it to then copy contents off of it.

http://en.wikipedia....ok_(CD_standard)

Im not sure how that applies with respect to DVD's or even Blueray, which probably have their own standards.

Edited by digip
Link to comment
Share on other sites

The directory is D:, and i tried it the directory as \\.\D: because i read somewhere that that's how you are ment to access logical drives but that dident work ether it just said that the parameter was in correct for this line


RandomAccessFile rawAccess = new RandomAccessFile( cd, "r" );
[/CODE]

i'm thinking that many the RandomFileAccess class cant access logical drives so ill have a look for a different class to read the data

Edited by danielbrthwt
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...