1. Stream Zoo 的基礎:四個抽象類,InputStream, OutputStream, Reader, Writer
其中后面兩個使用于Unicode文本。
2. 四個接口
interface Closeable {void close() throws IOException}
interface Flushable {void flush() throws IOException}
這兩個比較簡單
interface Readable {int read(CharBuffer cb)}
其中CharBuffer提供了支持連續/隨機讀寫操作的方法
Appendable接口有兩個方法,用于追加單個字符或一列字符
Appendable append(char c)
Appendalbe append(CharSequence s)
CharSequence是另一個接口。
java.lang.CharSequence 1.4
char charAt(int index)
int length()
CharSequence subSequence(int startIndex, int endIndex)
String toString()
3. FileInputStream和FileOutputStream
構造方法:
FileInputStream fin = new FileInputStream("employee.dat");
或
File f = new File("employee.dat");
FileInputStream fin = new FileInputStream(f);
注意輸入Windows文件路徑的時候使用雙\\,如"C:\\Windows\\a.ini",不過也可以是"c:/Windows/a.ini",不過這并不被提倡。
讀入一個字節:byte b = (byte) fin.read();
3. System.getProperty 方法
public static String getProperty(String key)
返回key值對應的屬性
Key |
Description of Associated Value |
java.version |
Java Runtime Environment version |
java.vendor |
Java Runtime Environment vendor |
java.vendor.url |
Java vendor URL |
java.home |
Java installation directory |
java.vm.specification.version |
Java Virtual Machine specification version |
java.vm.specification.vendor |
Java Virtual Machine specification vendor |
java.vm.specification.name |
Java Virtual Machine specification name |
java.vm.version |
Java Virtual Machine implementation version |
java.vm.vendor |
Java Virtual Machine implementation vendor |
java.vm.name |
Java Virtual Machine implementation name |
java.specification.version |
Java Runtime Environment specification version |
java.specification.vendor |
Java Runtime Environment specification vendor |
java.specification.name |
Java Runtime Environment specification name |
java.class.version |
Java class format version number |
java.class.path |
Java class path |
java.library.path |
List of paths to search when loading libraries |
java.io.tmpdir |
Default temp file path |
java.compiler |
Name of JIT compiler to use |
java.ext.dirs |
Path of extension directory or directories |
os.name |
Operating system name |
os.arch |
Operating system architecture |
os.version |
Operating system version |
file.separator |
File separator ("/" on UNIX) |
path.separator |
Path separator (":" on UNIX) |
line.separator |
Line separator ("\n" on UNIX) |
user.name |
User's account name |
user.home |
User's home directory |
user.dir |
User's current working directory |
如要得到當前目錄,使用String dir = System.getProperty("user.dir");