import java.io.*;
import java.util.*;
 public class AverageFile 
 {
 public static void main(String[] args) 
 {
  File f = new File("d:\\1");
  int size = 1024;

  //取得.txt文件
  String[] fileList = f.list();
  Vector v = new Vector();
  for (int i = 0; i < fileList.length; i++)
  {
   if (fileList[i].endsWith(".txt")) 
   {
    try 
    {
      v.addElement(new FileInputStream(fileList[i]));
    } 
    catch (Exception e1) 
    {
      e1.printStackTrace();
    }
   }
  }

  //合并文件流
  SequenceInputStream sis = new SequenceInputStream(v.elements());
  BufferedInputStream bis = new BufferedInputStream(sis);

  try
  {
byte[] data = new byte[1];
int count = 0;
while (true)
{
    int num = 0;
    BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream((++count) + ".txt"));
    while (bis.read(data) != -1)
    {
     bos.write(data);
     num++;
     if (num == size)
     {
      bos.flush();
      bos.close();
      break;
     }
    }
    if (num < size)
    {
     bos.flush();
     bos.close();
     break;
    }
   }
  } 
  catch (Exception e2)
  {
   e2.printStackTrace();
  }
 }
}
老大们,老是提示 
java.io.FileNotFoundException: test.txt (系统找不到指定的文件。)但是我的D;\1下面的确有文件啊TXT格式的.郁闷死.请各位帮忙调调

解决方案 »

  1.   

    这样写:     d:\\1.txt
      

  2.   

    不好意思   看错了    
     你试试   这样写if(fileList[i].isFile()&&fileList[i].getName().endWith(".txt"))
      

  3.   

    更正   if(fileList[i].isFile()&&fileList[i].getName().endsWith(".txt"))
      

  4.   

    PS;我自己又改了改才好的。不过给我的提醒不错。
    上面我定义的fileList 是String .改成File的.OK了。