IO 字节流学习
2024-08-31 01:36:29
复制图片和MP3
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException; public class inputstream { /**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
//test1();//复制图片
test2();//复制MP3
}
static void test1(){
FileInputStream fis = null;
FileOutputStream fos = null;
try {
fis = new FileInputStream("F:\\0.jpg");
fos = new FileOutputStream("F:\\fd.jpg");
byte[] byte1 = new byte[1024];
int x = 0;
while((x = fis.read(byte1))!=-1){
fos.write(byte1, 0, x);
} } catch (IOException e) {
// TODO: handle exception
}
finally{
try {
if(fis != null)
fis.close();
} catch (IOException e2) {
// TODO: handle exception
}
try {
if(fos!=null)
fos.close();
} catch (IOException e2) {
// TODO: handle exception
}
}
}
static void test2(){
BufferedInputStream bufi = null;
BufferedOutputStream bufo = null;
try {
bufi = new BufferedInputStream(new FileInputStream("F:\\fd.mp3"));
bufo = new BufferedOutputStream(new FileOutputStream("F:\\wzz.mp3"));
byte[] b = new byte[1024];
int x = 0;
while((x=bufi.read(b))!=-1){
bufo.write(b, 0, x);
}
} catch (IOException e) {
// TODO: handle exception
}
finally{
try {
if(bufi!=null)
bufi.close();
} catch (IOException e2) {
// TODO: handle exception
}
try {
if(bufo!=null)
bufo.close();
} catch (IOException e2) {
// TODO: handle exception
}
}
}
}
最新文章
- CentOS 6安装PostgreSQL
- [Linux] LVM的条带化
- Hive tuning tips
- [转] java书籍(给Java程序猿们推荐一些值得一看的好书 + 7本免费的Java电子书和教程 )
- SQL 分组排序分页(大神帮写的膜拜一下)
- NGINX(三)HASH表
- asp:时间的计算
- Redis介绍
- CSS and JavaScript Bundling and Minification in ASP.NET 4.5
- (转) c++ 迭代器
- errorPlacement的位置问题
- 页面设计-数据列表 DataGrid
- (扩展根目录容量方法汇总)把Linux系统迁移到另一个分区或者硬盘
- java中解析excel 批量插入数据库
- Girls and Boys HDU - 1068 二分图匹配(匈牙利)+最大独立集证明
- jenkins默认会存放目录
- 如何打jar包
- LeetCode - Top K Frequent Words
- 关联与下钻:快速定位MySQL性能瓶颈的制胜手段
- rpm 安装zabbix 注意