23.07.2013 Views

Java IO.pdf - Nguyen Dang Binh

Java IO.pdf - Nguyen Dang Binh

Java IO.pdf - Nguyen Dang Binh

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Java</strong> I/O<br />

complete list of the ASCII characters between 32 and 127 that must be encoded. For readers<br />

not familiar with Macintosh files, let me emphasize that this is purely for use inside <strong>Java</strong>.<br />

Native Macintosh code and the native Mac interface use the actual characters. As well as the<br />

characters listed here, all the upper 128 characters with their high bit set—that is, characters<br />

like and © and é—must be encoded. A little surprisingly, control characters between and 31<br />

are not encoded.<br />

Table 12.2. Hex-Encoded Characters in Macintosh Filenames<br />

Character Encoded As Decimal Value<br />

space %20 32<br />

# %23 35<br />

% %25 37<br />

/ %2f 47<br />

< %3c 60<br />

= %3d 61<br />

> %3e 62<br />

? %3f 63<br />

@ %40 64<br />

[ %5b 91<br />

\ %5c 92<br />

] %5d 93<br />

^ %5e 94<br />

` %60 96<br />

{ %7b 123<br />

| %7c 124<br />

} %7d 125<br />

~ %7e 126<br />

You probably don't need to know about the encoding at this level of detail unless you're trying<br />

to manipulate filenames manually—for example, walking directories by looking for separator<br />

characters rather than calling getParent(). The more you let <strong>Java</strong> do the work for you, the<br />

better off you'll be. As long as you use the methods of the File class rather than parsing<br />

pathnames directly as strings, this encoding scheme should be transparent.<br />

12.2.2 Relative Versus Absolute Paths<br />

There are two ways to reference a file, relative and absolute. Absolute addressing gives a<br />

complete path to a file, starting with the disk or root of the filesystem and working its way<br />

down. C:\PUBLIC\HTML\ JAVAFAQ\INDEX.HTM, Macintosh HD:<br />

public:html:javafaq:index.htm, and /public/html/javafaq/index.htm are all examples of<br />

absolute paths. Relative addressing does not use a complete path to a file; instead, it specifies<br />

the path relative to the current working directory. A relative pathname may point to a file in<br />

the current working directory by giving its name alone; other times it may point to a file in a<br />

subdirectory of the current working directory by giving the name of the subdirectory and the<br />

name of the file, and it may point to the parent of the current working directory with the<br />

double period (..).<br />

277

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

Saved successfully!

Ooh no, something went wrong!