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 OutputEndiannessthe result is likely to be several choice words from the UNIX user regarding"stupid DOS programmers."In both scenarios, you lose, because you're not presenting data properly for theuser on a given platform.To resolve this issue, use the system property file.separator. You can use ittwo ways:String slash = System.getProperty("file.separator");System.out.println("I cannot find images" + slash + "smurf.gif");or, because the File class provides a static variable that's initialized tofile.separator's value:System.out.println("I cannot find images" +File.separator + "smurf.gif");The other path-related issue is how to represent "path sequences". For example:c:\windows;c:\bin/usr/local/bin:/binThe first is a Windows path sequence, while the second is from UNIX. Note theuse of semicolon (';') in the first and colon (':') in the second. These are called "pathseparation characters", and can be different from one platform to the next.Java provides a system property named path.separator, which is also loadedinto File.pathSeparator. If you need to construct a path sequence for a usermessage (for example "You need to set your CLASSPATH to ...") it will help theuser a great deal to use the proper path separation character.System.out.println("CLASSPATH should be set to");System.out.println(" " + dir1 + File.pathSeparator + dir2);The last major platform concern is its Endianness.Many primitive data types, such as int, require multiple bytes to hold theirvalue. There are two ways a machine can order these multi-byte quantities whenwriting them to a file: most-significant byte (MSB) first, or least-significant byte(LSB) first. The MSB-first scheme is known as the "Big-Endian" approach,because the bytes are written "from the big end first". The LSB-first scheme isknown as "Little-Endian"; bytes are written "from the little end first."Java Input and Output -54© 1996-2003 jGuru.com. All Rights Reserved.

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

Saved successfully!

Ooh no, something went wrong!