genjava / tips / IO rules
Java Rules for I/O
Taken from the O'Reilly book by Eliotte Rusty Harold
- Never hard code pathnames.
- Ask user to name files.
- Use File.separatorChar not /
- Don't parse pathnames to find directories. Use java.io.File.
- Don't use renameTo() to move a file.
- Try to avoid copying and moving from java.
- Use System.getProperty("user.dir") and not '.'
- Use getParent() and not '..'
- Don't assume .class files are off of the cwd.
- Place data files in JARs rather than in filesystem. Load as resources from classpath.
- Never hurts to convert filenames to canonical form.
- Don't assume anything about filesystems.
- Test code on as many filesystems as possible.