import java.io.FileInputStream;
import java.io.FileOutputStream;
存储文件
* IO流:永久存储(耗时)}
// method2基本的字节流一次读取一个字节数组
private static void method2(String src, String dest) throws Exception {
//封装文件
FileInputStream fis = new FileInputStream(src) ;
FileOutputStream fos = new FileOutputStream(dest) ;
//读写操作
byte[] bys = new byte[1024] ;//相当于一个缓冲区
int len = 0 ;
while((len=fis.read(bys))!=-1) {
fos.write(bys, 0, len);
}
//释放资源
fis.close();
fos.close();
}
//method3高效的字节流一次读取一个字节
private static void method3(String src, String dest) throws Exception {
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(src)) ;
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(dest)) ;
//一次读个字节
int by = 0 ;
while((by=bis.read())!=-1) {
bos.write(by);
}
//释放资源
bis.close();
bos.close();
}
//method4高效的流一次读取一个字节数组
private static void method4(String src, String dest) throws Exception {
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(src)) ;
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(dest)) ;
//一次读取一个字节数组
byte[] bys = new byte[1024] ;
int len = 0 ;
while((len=bis.read(bys))!=-1) {
bos.write(bys, 0, len);
}
bis.close();
bos.close();