您的位置:首页 > 其它

数据流

2015-08-28 22:57 176 查看
public void copy(){

InputStream in=null;

OutputStream out=null;

try {

//建立读取和写入流

in=new FileInputStream("src\\mapTest\\test.txt");

out=new FileOutputStream("pro.txt");

int len=0;

byte[] by=new byte[1024];

while((len=in.read(by))!=-1){

//写入byte数组中的数据,读了几个字节就写入几个字节

out.write(by,0,len);

}

} catch (Exception e) {

e.printStackTrace();

}finally{

try {

//关闭流,后建立先关闭

out.close();

in.close();

} catch (IOException e) {

e.printStackTrace();

}

}

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