如题 出现了这个问题 求大侠指点 !!!- package cn.itcast.File.dl;
- import java.io.File;
- public class mergeFile3 {
-
- /**
- * @param args
- * @throws IOException
- */
- public static void main(String[] args) throws IOException {
- // TODO Auto-generated method stub
- File[] files=new File("e:\\a\\a").listFiles();
-
- Set<InputStream> inputStream = new TreeSet<InputStream>(new myComparator());
-
-
- for(File file : files){
- inputStream.add(new FileInputStream(file.getAbsolutePath()));
- System.out.println(file.getAbsolutePath());
- }
-
-
-
- final Iterator<InputStream> iterator = inputStream.iterator();
- InputStream in = new SequenceInputStream(new Enumeration<InputStream>() {
- @Override
- public boolean hasMoreElements() {
- // TODO Auto-generated method stub
- return iterator.hasNext();
- }
- @Override
- public InputStream nextElement() {
- // TODO Auto-generated method stub
- return iterator.next();
- }
- });
-
- OutputStream out = new FileOutputStream("e:\\a\\newA.jpg");
-
-
- byte[] buffer = new byte[1024];
- int len;
- while((len=in.read(buffer))!=-1){
- out.write(buffer, 0, len);
- }
- in.close();
- out.close();
-
- }
- }
- class myComparator implements Comparator<InputStream>{
-
-
- @Override
- public int compare(InputStream o1, InputStream o2) {
- // TODO Auto-generated method stub
- return 0;
- }
-
- }
复制代码 |