I have a file share on another machine that can be accesses using UNC paths such as
\\machine01\sharefldr\resources\hydrant.jpg
In one part of my code, I am already accessing files in this location. I making a separate thing and wanted to access a file similarly but my new code can't seem to access the same location. Wondering what might be missing from my new code that I am taking for granted in my original code.
code i've tried
String fileName = "hydrant.jpg";
String dataPath = "//machine01/sharefldr/";
String rscsDir = "resources";
Path myFilePath = Paths.get(dataPath, rscsDir, fileName);
System.out.println("Testing path:" + myFilePath.toString());
Boolean pExists = Files.exists(myFilePath);
System.out.println("Path Exists:" + pExists);
File dFile = myFilePath.toFile();
System.out.println("dFile Exists:" + dFile.exists());
System.out.println("Testing UNC path:" + Paths.get(dataPath).toString());
pExists = Files.exists( Paths.get(dataPath));
System.out.println("Path Exists:" + pExists);
System.out.println("Testing mapped path:" + Paths.get("T:\\").toString());
pExists = Files.exists( Paths.get("T:\\"));
System.out.println("Path Exists:" + pExists);
try {
Path file1 = Paths.get(dataPath, rscsDir, fileName);
System.out.println("Getting image width of file: "+file1.toString());
BufferedImage img1 = ImageIO.read(file1.toFile());
System.out.println("Image width:"+img1.getWidth());
}
catch (IOException x) {
System.out.println(x.getStackTrace());
}
try {
Path dir1 = Paths.get(dataPath, rscsDir);
Path filePath = dir1.resolve(fileName);
System.out.println("Getting image width of file2: "+filePath.toString());
BufferedImage img1 = ImageIO.read(filePath.toFile());
System.out.println("Image width:"+img1.getWidth());
}
catch (IOException x) {
System.out.println(x.getStackTrace());
}
output
Testing path:\\machine01\sharefldr\resources\hydrant.jpg
Path Exists:false
dFile Exists:false
Testing UNC path:\\machine01\sharefldr\
Path Exists:false
Testing mapped path:T:\
Path Exists:false
Getting image width of file: \\machine01\sharefldr\resources\hydrant.jpg
javax.imageio.IIOException: Can't read input file!
+ CategoryInfo : NotSpecified: (javax.imageio.I...ead input file!:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
+ PSComputerName : TestTargetW10B
at java.desktop/javax.imageio.ImageIO.read(ImageIO.java:1308)
NotSpecified: (:) [], RemoteException
...
Getting image width of file2: \\machine01\sharefldr\resources\hydrant.jpg
javax.imageio.IIOException: Can't read input file!
NotSpecified: (:) [], RemoteException