#5: File systems look like Unix
- The file separator may not be /
- The current directory may not be where you expect.
- Absolute paths may not begin with a file separator.
- . may not refer to the current directory.
- .. may not refer to the parent of the current directory
- / may not be the root of the file system.
- Copying and moving files often involves more than
reading the data in the old location and writing it in the new location.
- /tmp and /usr/tmp may not be real files
- /dev/null may be a real file
Fixes
- 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 current directory.
-
use the
System.getProperty("user.dir")
method
- .. 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)
- Copying and moving files often involves more than
reading the data in the old location and writing it in the new location.
-
No good solution in pure Java.
You really have to use native code.
- /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 com.macfaq.io.NullOutputStream
Previous | Next | Top
Other Presentations
| Cafe au Lait Home
Last Modified May 19, 1999
Copyright 1999 Elliotte Rusty Harold
elharo@metalab.unc.edu