IO流 文件的切割和合并
2016-01-24 14:40
246 查看
package com.yyq; import java.io.*; import java.util.*; /* * 切割流 * */ public class SplitFile { public static void main(String[] args) throws IOException { // TODO Auto-generated method stub splitFile(); merge(); } public static void merge() throws IOException{ ArrayList<FileInputStream>al = new ArrayList<FileInputStream>(); for(int x = 1;x<=3;x++){ al.add(new FileInputStream(x+".MYpart")); } Iterator<FileInputStream> it = al.iterator(); final Enumeration<FileInputStream> en = new Enumeration<FileInputStream>(){ public boolean hasMoreElements(){ return it.hasNext(); } public FileInputStream nextElement(){ return it.next(); } }; // 获取一个圆 SequenceInputStream sis = new SequenceInputStream(en); FileOutputStream fos = new FileOutputStream("0.jpg"); byte[] buf = new byte[1024]; int len = 0; while((len = sis.read(buf))!=-1){ fos.write(buf,0,len); } fos.close(); sis.close(); } public static void splitFile() throws IOException{ FileInputStream fis = new FileInputStream("1.jpg"); FileOutputStream fos =null; byte[] buf = new byte[1024*1024]; int len = 0; int count = 1; while((len = fis.read(buf))!=-1){ fos = new FileOutputStream(""+count+++".MYpart"); //File file = new file(""+count+++".part"); fos.write(buf,0,len); fos.close(); File file = new File(""+count+".part"); file.delete(); } if(fos!=null){ fos.close(); } } }
相关文章推荐
- redis集群
- Greedy:Graveyard Design(POJ 2100)
- nil、Nil、NULL与NSNull的区别--备用
- 通过vbscript批量更新excel文档oracle数据源(版本1:connection.refresh方法)
- uva10881 - Piotr's Ants (等效变换)
- Java并发编程:阻塞队列及实现生产者-消费者模式
- ZOJ 2812 Quicksum
- 使用开源中国(码云)托管代码
- Android之广播三(发送自定义广播)
- mysql 中文乱码问题
- 霸道厨男出世传记一懒人版糖醋排骨
- 贪心&合并果子
- QT结合opencv框架搭建
- 2015年第六届蓝桥杯C/C++程序设计本科B组省赛 移动距离(编程大题)
- 年终总结的写作方法及技巧
- VC6.0入门使用
- 科目二有惊无险
- hadoop - hadoop2.6 分布式 - 集群环境搭建 - 系统搭建和网络配置
- 黑马程序员-集合 (上)
- iOS开发之运行时编程(Runtime Programming)浅读