0

I have been trying to write an Audio CD ripper in Java so I can learn how they work. I can't seem to figure out how to actually read the songs off CD drive. I have managed to open the .cda files but there not very useful unless I can access the sectors on the CD. I've tried to open the D: drive (which is the CD drive on my computer) using the code below, but it gives File Not Found errors. I'm guessing this is because the CD drive is not a file. Is there any other type of Input Stream or is there a different way I can read from the CD drive. I've been searching for a long time and there is nothing that I can find that would help.

public class learning 
{
    public static void main(String[] args) throws IOException 
    {   
        FileInputStream input = new FileInputStream( "D:\\" );
    }
}

The specific error message is :

Exception in thread "main" java.io.FileNotFoundException: D:\ (The system cannot find the path specified)
    at java.io.FileInputStream.open(Native Method)
    at java.io.FileInputStream.<init>(Unknown Source)
    at java.io.FileInputStream.<init>(Unknown Source)
    at learning.main(learning.java:5)

Cheers Daniel

Hans Then
  • 10,935
  • 3
  • 32
  • 51

1 Answers1

0

There is an OS project for this: Ripper.

The magic is in the GrabEncodePanel.java, in the getCDDADir() and getCDDAStream() functions (I'm afraid to post the actual source, as then I'd have to post the license too...)

EDIT I learnt something today too: this is only straightforward on Linux according to this FAQ

ppeterka
  • 20,583
  • 6
  • 63
  • 78
  • When i tried to use "URL url = new URL("cdda:/dev/cdrom");" is said "unknown protocol : cdda" – Daniel Braithwaite Oct 26 '12 at 10:10
  • @DanielBraithwaite I edited my answer, it seems that this method works only in Linux... – ppeterka Oct 26 '12 at 11:38
  • Well, it's kinda the same on any OS: Get a handle to the actual device and read off it. It's just that Unix-likes have those in the accessible file system whereas e.g. Windows has a higher-level hierarchy containing those, usually unavailable to abstractions such as Java. – Joey Oct 26 '12 at 12:31