1

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
Eelke
  • 21
  • 6
  • where this code runs? in Linux or Windows? – Qingfei Yuan Jul 16 '19 at 19:50
  • windows, sorry, that was in the title – Eelke Jul 16 '19 at 20:02
  • what do you mean `accessible from one part but not other part`? There must be something else difference. – Qingfei Yuan Jul 16 '19 at 20:05
  • I must also add, I just did a test and found out the original code is NOT accessing the same location like I thought. Looking into it further. Current issue might be configuration thing. Sorry for my confusion. Might be a double hop credential thing as the java application is being launched remotely via powershell and such. Regardless, any ideas around this are appreciated. – Eelke Jul 16 '19 at 20:06
  • the exists thing may or may not work - but if the imageio bombs then you dont have the file. these slashes a/b/c work for normal thing - I dont know how it works on UNC but if you dont have the file there you dont have the file there – gpasch Jul 16 '19 at 21:56

0 Answers0