Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problems with java and reading data from a CD drive in linux

Tags:

java

ripping

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

like image 419
Daniel Braithwaite Avatar asked Oct 14 '12 04:10

Daniel Braithwaite


People also ask

What is cdrom in Linux?

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.


1 Answers

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).

like image 54
Rija Ramampiandra Avatar answered Oct 17 '22 01:10

Rija Ramampiandra