13.07.2015 Views

I/O Fundamentals

I/O Fundamentals

I/O Fundamentals

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Java Input and OutputFile Name Lengthwork just about anywhere.This can be a very tricky thing to get right. Suppose you were writing a programon UNIX, which allows very long file names. If you take advantage of thiscapability, you could encounter file I/O errors on other platforms.The absolutely safest approach is to restrict file names to the 8.3 file namescheme. Have no more than 8 characters before a ".", only a single ".", and no morethan three characters after the ".". It can be ugly, but it will work.Many platforms have limits on the length of the path specification of a file. Becareful of very deeply nested files in the file system. You might not be able to drilldown far enough to find them.This limitation is of particular concern if you are walking through a hierarchy andbuilding the path names as you go. Depending on how you build them, you mightend up with a name likesome/directory/../where/../over/../here/../../images/foo.gifrather than the more directimages/foo.gifThis can be a very easy trap to fall into.File Name Case SensitivitySome platforms, like UNIX, provide case sensitivity in file names. The nameslittleMissMuffet.txt, LittleMissMuffet.txt, and littleMissMuffet.TXTrepresent unique files. On other systems, such as Windows, these names all referto the same file.This can become a significant problem in a Java program. Take the following codeas an example:FileWriter writer = new FileWriter("littleMissMuffet.txt");writer.write("Some text");writer.close();// ... lots of code in between to hide the difference ...BufferedReader reader = new BufferedReader(new FileReader("LittleMissMuffet.txt"));Java Input and Output -50© 1996-2003 jGuru.com. All Rights Reserved.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!