您的位置:首页 > 编程语言 > Java开发

使用java输入输出流实现文件的复制:

2014-03-15 23:08 281 查看
public class Test {

public static void copy(File source,File target){

InputStream in=null;

OutputStream out=null;

try {

in=new BufferedInputStream(new FileInputStream(source));

out=new BufferedOutputStream(new FileOutputStream(target));

byte[] buff=new byte[1024];

while(in.read(buff)>0){

out.write(buff);

}

} catch (Exception e) {

// TODO: handle exception

e.printStackTrace();

}finally{

try {

if(in!=null)

in.close();

if(out!=null)

out.close();

} catch (Exception e2) {

// TODO: handle exception

}

}

}

public static void main(String[] args) {

// TODO Auto-generated method stub

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: