- 浏览: 216498 次
- 性别:
- 来自: 上海
文章分类
最新评论
-
junzi2013:
df
黑马程序员:MyEclipse9 常用快捷键 中英文对照 及 快速get set方法 -
junzi2013:
dfsdafadsfsd
黑马程序员:MyEclipse9 常用快捷键 中英文对照 及 快速get set方法 -
idealab:
博主说的OpenCSV, JavaCSV, SuperCSV都 ...
csv调研 -
tanxin:
楼主怎么解决这个问题的呢?
坑爹的zookeer -
yy22258867:
:twisted:
黑马程序员19-7:foreach遍历核心源码,遍历HashMap需要用map.keySet()或map.entrySet()
package cn.itcast.io.p1.splitfile; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.SequenceInputStream; import java.util.ArrayList; import java.util.Collections; import java.util.Enumeration; import java.util.Properties; public class MergeFile { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { File dir = new File("c:\\partfiles"); mergeFile_2(dir); } //根据配置文件合并分割文件 public static void mergeFile_2(File dir) throws IOException { /* * 获取指定目录下的配置文件对象。 */ //自定义扩展名过滤器,实现了FilenameFilter File[] files = dir.listFiles(new SuffixFilter(".properties")); if(files.length!=1) throw new RuntimeException(dir+",该目录下没有properties扩展名的文件或者不唯一"); //记录配置文件对象。 File confile = files[0]; //获取该文件中的信息================================================。 Properties prop = new Properties(); FileInputStream fis = new FileInputStream(confile); prop.load(fis); String filename = prop.getProperty("filename"); int count = Integer.parseInt(prop.getProperty("partcount")); //获取该目录下的所有碎片文件。 ============================================== File[] partFiles = dir.listFiles(new SuffixFilter(".part")); if(partFiles.length!=(count-1)){ throw new RuntimeException(" 碎片文件不符合要求,个数不对!应该"+count+"个"); } //将碎片文件和流对象关联 并存储到集合中。 ArrayList<FileInputStream> al = new ArrayList<FileInputStream>(); for(int x=0; x<partFiles.length; x++){ al.add(new FileInputStream(partFiles[x])); } //将多个流合并成一个序列流。 Enumeration<FileInputStream> en = Collections.enumeration(al); SequenceInputStream sis = new SequenceInputStream(en); FileOutputStream fos = new FileOutputStream(new File(dir,filename)); 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 mergeFile(File dir) throws IOException{ ArrayList<FileInputStream> al = new ArrayList<FileInputStream>(); for(int x=1; x<=3 ;x++){ al.add(new FileInputStream(new File(dir,x+".part"))); } Enumeration<FileInputStream> en = Collections.enumeration(al); SequenceInputStream :x sis = new SequenceInputStream(en); FileOutputStream fos = new FileOutputStream(new File(dir,"1.bmp")); byte[] buf = new byte[1024]; int len = 0; while((len=sis.read(buf))!=-1){ fos.write(buf,0,len); } fos.close(); sis.close(); } }
package cn.itcast.io.p1.splitfile; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.util.Properties; /* * 文件切割器。 * * * * */ public class SplitFileDemo { private static final int SIZE = 1024 * 1024; /** * @param args * @throws Exception */ public static void main(String[] args) throws Exception { File file = new File("c:\\aa.mp3"); splitFile_2(file); } private static void splitFile_2(File file) throws IOException { // 用读取流关联源文件。 FileInputStream fis = new FileInputStream(file); // 定义一个1M的缓冲区。 byte[] buf = new byte[SIZE]; // 创建目的。 FileOutputStream fos = null; int len = 0; int count = 1; /* * 切割文件时,必须记录住被切割文件的名称,以及切割出来碎片文件的个数。 以方便于合并。 * 这个信息为了进行描述,使用键值对的方式。用到了properties对象 * */ Properties prop = new Properties(); File dir = new File("c:\\partfiles"); if (!dir.exists()) dir.mkdirs(); while ((len = fis.read(buf)) != -1) { fos = new FileOutputStream(new File(dir, (count++) + ".part")); fos.write(buf, 0, len); fos.close(); } //将被切割文件的信息保存到prop集合中。 prop.setProperty("partcount", count+""); prop.setProperty("filename", file.getName()); fos = new FileOutputStream(new File(dir,count+".properties")); //将prop集合中的数据存储到文件中。 prop.store(fos, "save file info"); fos.close(); fis.close(); } public static void splitFile(File file) throws IOException { // 用读取流关联源文件。 FileInputStream fis = new FileInputStream(file); // 定义一个1M的缓冲区。 byte[] buf = new byte[SIZE]; // 创建目的。 FileOutputStream fos = null; int len = 0; int count = 1; File dir = new File("c:\\partfiles"); if (!dir.exists()) dir.mkdirs(); while ((len = fis.read(buf)) != -1) { fos = new FileOutputStream(new File(dir, (count++) + ".part")); fos.write(buf, 0, len); } fos.close(); fis.close(); } }
package cn.itcast.io.p1.splitfile; import java.io.File; import java.io.FilenameFilter; public class SuffixFilter implements FilenameFilter { private String suffix; public SuffixFilter(String suffix) { super(); this.suffix = suffix; } @Override public boolean accept(File dir, String name) { return name.endsWith(suffix); } }
详细请查看:http://edu.csdn.net/heima -------
发表评论
-
Java中的IO整理完整版
2013-02-15 17:23 667http://developer.51cto.com/art/ ... -
Myeclipse中导入zip文件查看源代码
2012-09-21 23:35 1005用Myeclipse的时候,出现无法查看源码的话,导入jdk文 ... -
==与equals
2012-09-13 20:15 600一般基本数据类型的比较用 == 当涉及到对象、字符串的时候,就 ... -
多线程课程002:线程范围内的共享变量
2012-09-13 16:47 911package cn.itcast.heima2; ... -
多线程课程001:线程安全的问题
2012-09-13 14:37 775下面的做法,会发现输出结果被打断了。 package co ... -
多线程课程001:线程安全的问题
2012-09-13 11:14 757package com.lee.thread; pu ... -
内部类的实际应用
2012-09-13 11:01 627public class TraditionalThreadS ... -
Java接口
2012-09-11 12:07 727Java接口的方法只能是抽象的和公开的,Java接口不能有构造 ... -
移位运算符
2012-09-11 09:31 811移位运算符 <<左移 a<<b,a转 ... -
【总结】gridbaglayout布局管理器
2012-08-15 11:19 665http://blog.sina.com.cn/s/blog_ ... -
【练习_00010】java不重复随机数
2012-08-14 01:26 658package com.heima.test; impo ... -
【练习】判断一个字符串中某些字段出现的次数
2012-08-14 01:08 936package com.heima.test; im ... -
选择、冒泡、折半排序查找方法
2012-08-13 15:06 1178import java.util.Arrays; i ... -
自己写的杨辉三角
2012-08-12 16:41 770package com.lee.graphic; p ... -
交换两个数的位置,不用中间变量
2012-08-06 02:28 1081a ^= b; b ^= a; a ^= b; 1 ... -
未解问题,定时器无法自定义切换时间
2012-07-30 18:08 981package com.heima.test004.enu ... -
黑马程序员:设计模式,享元模式flyweight
2012-07-23 02:13 0如果有很多很小的东西,对象,当他们有很多属性是相同的,就可以把 ... -
黑马程序员:for综合图形整合结晶
2012-07-23 01:16 778package Graph; public clas ... -
JS: js获取字符串长度
2012-07-20 18:01 0<SCRIPT LANGUAGE="Jav ... -
传智27-2: 模拟Tocat浏览器,写网页蜘蛛爬虫,抓取网页信息
2012-07-12 17:03 0package cn.itcast.net.p2.ie_s ...
相关推荐
将多个读取流合并成一个读取流,可以方便操作多个读取流。原理(迭代器)。 OutputStream |--FileOutputStream/:文件输出流。用于将写入File和FileDescriptor的输出流。用来操作图像,声音,视频等原始字节流。 ...
2、常用21个IO流:FileWriter、FileReader、CharArrayReader、CharArrayWriter、CharSequence、OutputStreamWriter、FileOutputStream、InputStreamReader、PrintWriter、BufferedReader、InputStream、...
5) SequenceInputStream:把多个InputStream合并为一个InputStream 2) Out stream 1) ByteArrayOutputStream:把信息存入内存中的一个缓冲区中 2) FileOutputStream:把信息存入文件中 3) PipedOutputStream:实现...
4)SequenceInputStream:这个类可以将几个输入流串联在一起合并为一个输入流,构造函数有: SequenceInputStream(Enumeration e)枚举类型e中包含了若干个要被串联的输入流 SequenceInputStream(InputStream s1, ...
File类保存文件或目录的各种元数据信息,包括文件名、文件长度、最后修改时间、是否可读、获取当前文件的路径名,判断指定文件是否存在、获得当前目录中的文件列表,创建、删除文件和目录等方法。 9....
1. stream代表的是任何有能力产出数据的数据源,或是任何有能力接收数据的接收源。在Java的IO中,所有的stream(包括Input和Out stream)都包括两种类型: 1.1 以字节为导向的stream 以字节为导向的stream,表示以...
5) SequenceInputStream:把多个InputStream合并为一个InputStream 2) Out stream 1) ByteArrayOutputStream:把信息存入内存中的一个缓冲区中 2) FileOutputStream:把信息存入文件中 3) PipedOutputStream:实现...
PCMAudioPlayerDemothis project Using AudioTrack play PCM audio files##chinese这里要感谢...##说明该demo实现将多个pcm的音频文件合并到一个流中(合并主要用的是SequenceInputStream),通过用AudioTrack进行播放。