数据流
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();
}
}
}
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();
}
}
}
相关文章推荐
- [C语言][LeetCode][73]Set Matrix Zeroes
- strerror函数
- 自定义pickview的高度
- 【Objective-C】01-面向对象
- [cocos2d-x] --- 完美解决中文乱码
- Ionic项目中使用极光推送-android
- 隐藏CListCtrl滚动条
- ios开发进阶之多线程03 RunLoop 网络编程
- cocoa之高级开发RunTime初级基本变数
- 播布客全套视频
- JSON深入浅出
- ACM_素数筛法 唯一分解定理 欧拉函数(附容斥)
- JMS和ActiveMQ
- 两个变量进行交换
- 元素的引用
- 在浏览器控制台输出图片
- Mpich编程
- XUtils下BitmapUtils全部注释
- Valid Parentheses
- 什么是NumPy