I have been trying to write a simple audio ripper that i can use to learn how diffrent CODEC's work but i have got stuck on the first step, i cant get my program to read from the CD, the folowing code is what i have been trying to use
import java.io.File;
import java.io.FileInputStream;
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( "/dev/sr0" );
RandomAccessFile rawAccess = new RandomAccessFile( cd, "r" );
byte[] content = new byte[20];
rawAccess.seek(19613);
rawAccess.readFully(content);
System.out.println(content);
}
}
but it gives me the folowing error
Exception in thread "main" java.io.IOException: Input/output error
at java.io.RandomAccessFile.readBytes(Native Method)
at java.io.RandomAccessFile.read(RandomAccessFile.java:355)
at java.io.RandomAccessFile.readFully(RandomAccessFile.java:414)
at java.io.RandomAccessFile.readFully(RandomAccessFile.java:394)
at learning.main(learning.java:21)
and i cant figure out why i get this, i though maby RandomFileAccess wasn't the right class to use but the only thing i could find said this should work
Any help on how to read CD's from java would be much appreciated.
Cheers Daniel
In this example, /cdrom is the CD-ROM mount point directory, which must exist, and /dev/disk/cdrom0c is the CD-ROM device name. If the Installer is displaying the Disk Location dialog box, enter the CD-ROM mount point directory path, for example: /cdrom.
First of all you should mount on a directory which the user logged in the OS Linux have access. E.g. : /mnt/cdrom or /media/cdrom
After that open your mp3 file or audio file :
File cd = new File( "/dev/sr0/track1.mp3" );
or
File cd = new File( "/dev/sr0/track1.dat" );
(don't forget the extension of the Audio or Mp3 file).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With