Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UNC Path .exists() returns false

Tags:

java

Why does this return false in java?

new File("\\\\10.10.1.4").exists() 

but

new File("\\\\10.10.1.4\\dir").exists() 

returns true.

If i open the first address (without 'dir') in windows explorer i see the content so i don't think it's a permission issue since windows can see it just fine

Same thing happens with File.listFiles(). The first address returns null but the second returns the actual content

Finally if all else fails, is there any other way to test if a UNC address (just the ip without directory) exists and to list its content?

like image 468
Hilikus Avatar asked Apr 18 '26 00:04

Hilikus


2 Answers

\\10.10.1.4 is an address, not a share reference, it does not point to a mounted file system. \\10.10.1.4\dir points to a share point which is a mounted file system.

I'd be like sending a letter to a street address, but leaving of the house number...it's not got a point of context from which it can be delievered. The same goes here. Java doesn't see \\10.10.14 as File, thus it doesn't exist (from the context of a File)

like image 61
MadProgrammer Avatar answered Apr 20 '26 13:04

MadProgrammer


File("\\10.10.1.4") doesn't exist.

File("\\10.10.1.4\") probably does.

The browser/explorer automatically adds the backslash and that's why it displays the contents.

like image 40
Razvan Avatar answered Apr 20 '26 14:04

Razvan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!