Java 1.6 - determine symbolic links -


In a DirectoryWalker class, I have to find out that a file instance is actually a symbolic link to a directory (assuming , Walker runs on Unix system), I already know that this is a directory, will there be the following reliable position to determine the symbolic link?

  file file; // ... if (file.getAbsolutePath (.) Equals (file.getCanonicalPath ()) // // Actual Directory --- & gt; Normal stuff} and {// possible symbolic link --- & gt; The technique used in Apache Commons uses Canonical Path for Parents, I / O directory, not the file itself; I do not think that you can guarantee that a mismatch is due to a symbolic link, but it A good indication is that the file requires special treatment.  

This (subject) is modified for compactness. Public Pure Boolean throws the symbolic file (IOException) {if (File == blank) New Nulloinction Exception ("File should not be empty"); File Canon; If (file.getParent () == faucet) {canon = file; } Other {file canonDir = file.getParentFile (). GetCanonicalFile (); Canon = new file (canondir, file.getName ()); } Return! Canon.getCanonicalFile (). Equal (canon.getAbsoluteFile ()); }


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -