2

I have a WD My Cloud at home. I can access it with my laptop from the file explorer just by typing Z:\path\to\image.jpg.

I'm writing a Java program that would read the image content located on this little cloud.

Here is my code:

Path p =Paths.get("\\\\192.168.1.2\\z$\\path\\to\\image.jpg");

try {
    byte[] data = Files.readAllBytes(p);

    // Process data here...
} catch (IOException e) {
    // ...
}

This program fails with the below exception :

java.nio.file.FileSystemException: \\192.168.1.2\z$\path\to\image.jpg: Nom de réseau introuvable.

"Nom de réseau introuvable" : “Network name not found”

I tried other paths without success:

  • \\localhost\z$\path\to\image.jpg
  • \\127.0.0.1\z$\path\to\image.jpg
  • \\MyPcName-PC\z$\path\to\image.jpg
  • Z:/path/to/image.jpg

What am I missing ?

Windows 10
Java 8

Stephan
  • 41,764
  • 65
  • 238
  • 329
  • UNC or SMB? I've had issues with SMB on Windows 8+ due to changes in the security management system – MadProgrammer Apr 25 '19 at 22:41
  • @MadProgrammer I tried https://github.com/AgNO3/jcifs-ng without success : something like `SmbFile sf = new SmbFile(pathHere)`. This constructor is deprecated and I didn't find an example with a non deprecated constructor. Today, I read `Path` could handle such paths. So far, it doesn't work for me. – Stephan Apr 25 '19 at 22:54

1 Answers1

0

Format the string in the Paths.get argument similar as is shown below.

package access.mounted.drive;

import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.Files;
import java.io.IOException;

/**
 * @author Charles
 */
public class AccessMountedDrive {

    public static void main(String[] args) {
        Path p =
        Paths.get("E:\\\\Photos Grandparents\\Scan0166a Rose Pincoffs.jpg");

        try {
            int i=0;
            byte[] data = Files.readAllBytes(p);
            System.out.println("File size in bytes:" + data.length);
            // Process data here...
        } catch (IOException e) {
            System.out.println("IOException: " + e);
        }
    }

}
Charles Knell
  • 342
  • 1
  • 7
  • The code raises this exception: `IOException: java.nio.file.NoSuchFileException: Z:\path\to\image.jpg` – Stephan Apr 29 '19 at 17:46
  • Did you find a solution? I have mounted the directory. How did you perform file operations? – Shubham Jan 11 '21 at 15:17