Easy to Learn Java: Programming Articles, Examples and Tips

Start with Java in a few days with Java Lessons or Lectures


Code Examples

Java Tools

More Java Tools!

Java Forum

All Java Tips


Submit News
Search the site here...
Search the JavaFAQ.nu
1000 Java Tips ebook

1000 Java Tips - Click here for the high resolution copy!1000 Java Tips - Click here for the high resolution copy!

Java Screensaver, take it here

Free "1000 Java Tips" eBook is here! It is huge collection of big and small Java programming articles and tips. Please take your copy here.

Take your copy of free "Java Technology Screensaver"!.

It is not a big secret that file system in Java looks like UNIX file system. It

JavaFAQ Home » General Java Go to all tips in General Java

Bookmark and Share

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 com.macfaq.io.NullOutputStream

? 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:

File, FileDescriptorFileFilter, FileInputStream, FilenameFilter,
FileNotFoundException, FileOutputStream, FilePermission, FileReader, FileWriter

 Printer Friendly Page  Printer Friendly Page
 Send to a Friend  Send to a Friend

.. Bookmark and Share

Search here again if you need more info!
Custom Search

Home Code Examples Java Forum All Java Tips Books Submit News, Code... Search... Offshore Software Tech Doodling

RSS feed Java FAQ RSS feed Java FAQ News     

    RSS feed Java Forums RSS feed Java Forums

All logos and trademarks in this site are property of their respective owner. The comments are property of their posters, all the rest 1999-2006 by Java FAQs Daily Tips.

Interactive software released under GNU GPL, Code Credits, Privacy Policy