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格式的.郁闷死.请各位帮忙调调
------解决方案--------------------
更正 if(fileList[i].isFile()&&fileList[i].getName().endsWith( ".txt "))