62,628
社区成员
发帖
与我相关
我的任务
分享package com.wonders.test;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
/**
* @author liyongyong
* 2016年12月28日
*/
public class FileOutputStreamTest {
public static void main(String[] args) {
FileInputStream fis = null;
FileOutputStream fos = null;
try {
//创建字节输入流 使用绝对路径
fis = new FileInputStream("E:\\workplace\\Test\\src\\com\\wonders\\test\\TestDog.java");
//创建字节输出流
fos = new FileOutputStream("E:\\workplace\\Test\\src\\com\\wonders\\test\\new.txt");
byte[] buf = new byte[32];
int hasRead = 0;
while((hasRead = fis.read(buf)) > 0){
fos.write(buf, 0, hasRead);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally{
if (fis != null) {
try {
fis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (fos != null) {
try {
fos.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
}