Tips in reading cd content in java?

Asked By 10 points N/A Posted on -
qa-featured

Hi there.  I'm trying to read folders and files on a CD  using Java.  I'm always having an error of  "Exception in thread "main" java.io.IOException:  Input/output error".  Can someone teach me the steps in reading CD content in Java?  I'm on OS Linux.  Thanks.

SHARE
Best Answer by Jose K Vincent
Best Answer
Best Answer
Answered By 60 points N/A #171730

Tips in reading cd content in java?

qa-featured

Hi Caroline,

At first you should mount a directory which user is accessing in OS linux. You can mount it like following :

Process MountSpace = Runtime.getRuntime().exec(Command)

And after that try to open the file which you want to access, i.e like this

File cd = new File( "/dev/SR0/tk1.mp3" );

 

Hope this will help.

Thanks.

Answered By 0 points N/A #171731

Tips in reading cd content in java?

qa-featured

This is the correct way to list all files in a directory. Replace [PATH] with your desired directory:

Path dir = …;

try (DirectoryStream[PATH] stream = Files.newDirectoryStream(dir)) {

     for (Path file: stream) {

           System.out.println(file.getFileName());

     }

} catch (IOException | DirectoryIteratorException x) {

      // IOException can never be thrown by the iteration.

      // In this snippet, it can only be thrown by newDirectoryStream. System.err.println(x); }

New versions of Java include specialized ways to list contents of a directory in more ways.

Login/Register to Answer

Related Questions