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.
Tips in reading cd content in java?
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.
Tips in reading cd content in java?
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.