genjava / tips / IO rules

Java Rules for I/O

Taken from the O'Reilly book by Eliotte Rusty Harold
  1. Never hard code pathnames.
  2. Ask user to name files.
  3. Use File.separatorChar not /
  4. Don't parse pathnames to find directories. Use java.io.File.
  5. Don't use renameTo() to move a file.
  6. Try to avoid copying and moving from java.
  7. Use System.getProperty("user.dir") and not '.'
  8. Use getParent() and not '..'
  9. Don't assume .class files are off of the cwd.
  10. Place data files in JARs rather than in filesystem. Load as resources from classpath.
  11. Never hurts to convert filenames to canonical form.
  12. Don't assume anything about filesystems.
  13. Test code on as many filesystems as possible.