1、read()
功能:讀取單個字符的個數,如果已經讀完的話會返回-1 (其范圍從 0 到 65535 )
例子如下:
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) { //單個讀取計數,直到結束返回-1
out.write(buf, 0, len);
}
in.close();
out.close();
2、readLine()
功能:讀取一個文本行。
例子如下:
String str;
while ((str = in.readLine()) != null) { //如果之前文件為空,則不執行輸出
System.out.println(str);
}
