?? filestreamdemo.java
字號:
package onlyfun.caterpillar;
import java.io.*;
public class FileStreamDemo {
public static void main(String[] args) {
try {
byte[] buffer = new byte[1024];
// 來源文件
FileInputStream fileInputStream =
new FileInputStream(new File(args[0]));
// 目的文件
FileOutputStream fileOutputStream =
new FileOutputStream(new File(args[1]));
// available()可取得未讀取的數據長度
System.out.println("復制文件:" +
fileInputStream.available() + "字節");
while(true) {
if(fileInputStream.available() < 1024) {
// 剩余的數據比1024字節少
// 一位一位讀出再寫入目的文件
int remain = -1;
while((remain = fileInputStream.read())
!= -1) {
fileOutputStream.write(remain);
}
break;
}
else {
// 從來源文件讀取數據至緩沖區
fileInputStream.read(buffer);
// 將數組數據寫入目的文件
fileOutputStream.write(buffer);
}
}
// 關閉流
fileInputStream.close();
fileOutputStream.close();
System.out.println("復制完成");
}
catch(ArrayIndexOutOfBoundsException e) {
System.out.println(
"using: java FileStreamDemo src des");
e.printStackTrace();
}
catch(IOException e) {
e.printStackTrace();
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -