Java IO课件.pdf
文本预览下载声明
The Java I/O System
Qiuyan Huo
Software Engineering Institute
qyhuo@mail.xidian.edu.cn
Java (SSXDU 2009)
Java Input/Output
I/O libraries are hard to design, and everyone can
find something to complain about.
Java ’s I/O library is extensive, and it seems like you
need to know 100 things before you can start using
it.
Today, let ’s learn some things and still do
something useful.
2
Java (SSXDU 2009)
#1: Why Is Java I/O Hard?
Java is intended to be used on many very different
machines, having
– different character encodings (ASCII, EBCDIC, 7- 8- or 16-
bit…)
– different internal numerical representations
– different file systems, so different filename pathname
conventions
– different arrangements for EOL, EOF, etc.
The Java I/O classes have to “stand between”your
code and all these different machines and
conventions.
3
Java (SSXDU 2009)
#2: Java’s Internal Characters
Unicode. 16-bit. Good idea.
So, the primitive type char is 16-bit.
Reading from a file using 8-bit ASCII characters (for
example) requires conversion.
Same for writing.
But binary files (e.g., graphics) are “byte-sized”, so
there is a primitive type byte.
So Java has two systems to handle the two
different requirements.
Both are in java.io, so import this always !
4
Java (SSXDU
显示全部