Question:Java File system looks like UNIX file system. It is understandable since the
language was developed by SUN.
But what is about the WORA principle "Write once - run everywhere"?
Answer: From the beginning, first
versions of Java it was right. I will list most common "beliefs" here and
comment them, where
? - "belief"
! - truth
? The file separator may not be /
! Use File.pathSeparator
? The current directory may not be where you expect.
! Ask the user to locate the file with a file dialog.
? Absolute paths may not begin with a file separator.
! Use the getCanonicalPath() method in the File class
? .. may not refer to the parent of the current directory
! use the getParent() method in the File class
? / may not be the root of the file system.
! Use File.listRoots() instead (Java 1.2)
? /tmp and /usr/tmp may not be real files
! Use File.createTempFile() instead (Java 1.2)
? /dev/null may be a real file
! Use a java.io.ByteArrayOutputStream or, better yet, a
? Copying and moving files often involves more than reading the data in the
old location and writing it in the new location.
?! Unfortunatelly it is a true... No good solution in pure Java. You really have
to use native code. My opinion is to use System call to OS methods like "cp" in
Unix, for example or "copy" in Windows...
Java File system code examples on our site you can find here:
69 comments | | Score: 4