黑马程序员技术交流社区
标题:
enumercation只能由Vector获得吗?
[打印本页]
作者:
清风有意
时间:
2014-4-19 19:48
标题:
enumercation只能由Vector获得吗?
enumercation还可以由其他集合获取吗?不是说Vector已经淘汰了,被ArrayList替代了吗?那ArrayList可以获取enumercation吗?
代码:
package IOTest;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.SequenceInputStream;
import java.util.Vector;
public class SequenceTest {
public static void main(String[] args) {
FileOutputStream fos=null;
SequenceInputStream sis=null;
Vector<FileInputStream> vector=new Vector<FileInputStream>();
try {
fos=new FileOutputStream("4.txt");
vector.add(new FileInputStream("2.txt"));
vector.add(new FileInputStream("1.txt"));
vector.add(new FileInputStream("3.txt"));
sis=new SequenceInputStream(vector.elements());
byte[] buf=new byte[1024];
int len=0;
while((len=sis.read(buf))!=-1)
{
fos.write(buf, 0, len);
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally{
try {
if(fos!=null)
fos.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
try {
if(sis!=null)
sis.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
}
复制代码
作者:
曹冬明
时间:
2014-4-19 19:51
毕老师的视频里好像说过,这哥们唯一存在的理由就是能获取枚举
作者:
清风有意
时间:
2014-4-19 20:11
曹冬明 发表于 2014-4-19 19:51
毕老师的视频里好像说过,这哥们唯一存在的理由就是能获取枚举
哦,我想起来了!
作者:
ノtrack
时间:
2014-4-19 22:09
/*
切割文件
合并文件
SequenceInputStream
*/
import java.io.*;
import java.util.*;
class Demo8
{
public static void main(String[] args)throws Exception
{
BufferedInputStream bis=new BufferedInputStream(new FileInputStream("Dj.mp3"));
BufferedOutputStream bos=null;
byte []buf=new byte[1024*1024*2];
int len=0;
int count=0;
while((len=bis.read(buf))!=-1){
bos=new BufferedOutputStream(new FileOutputStream("split/Dj_"+(++count)+".part"));
bos.write(buf,0,len);
bos.close();
}
ArrayList<InputStream> al=new ArrayList<InputStream>();
count=0;
while(count!=3){
al.add(new FileInputStream("split/Dj_"+(++count)+".part"));
}
final Iterator<InputStream> it=al.iterator();
Enumeration<InputStream> en=new Enumeration<InputStream>(){
public boolean hasMoreElements(){
return it.hasNext();
}
public InputStream nextElement(){
return it.next();
}
};
SequenceInputStream sis=new SequenceInputStream(en);
PrintStream ps=new PrintStream("split/Dj.mp3");
byte []b=new byte[1024];
len=0;
while((len=sis.read(b))!=-1){
ps.write(b,0,len);
}
if(bis!=null)
bis.close();
if(bos!=null)
bos.close();
sis.close();
ps.close();
}
}
复制代码
作者:
idream
时间:
2014-4-20 21:24
ArrayList不可以获取枚举,枚举是Vector特有的一种迭代方式
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2