Unfortunately, I do not see the possibility in the Java API for this.
I checked the Windows JRE code, and it looks like the solution is based on the file attributes themselves:
try { WindowsFileAttributes windowsfileattributes = WindowsFileAttributes.get(windowspath2, false); if(windowsfileattributes.isDirectory() || windowsfileattributes.isDirectoryLink()) i |= 1; }
The attributes themselves come from native code, and there seems to be no way to influence them.
Obviously, you have other options, such as manually accessing mklink or even controlling returned objects using something like PowerMock (which is clearly not intended for this purpose).
Another dirty option is to create proxies for all relevant classes: Path , FileSystem and FileSystemProvider .
The way it works is that Path returns a FileSystem , which FileSystemProvider returns - what you need to do is change the behavior of the FileSystemProvider.createSymbolicLink methods.
The createSymbolicLink method receives a varargs argument that is not currently used, you can pass an argument to it that tells your shell to override the way symbolic links are created - and here you are :)
After writing all this - the only question I have is - why do you need this behavior?
source share