文件合并器,帮忙看下那错
import java.io.*;
import java.util.*;
public class Test1
{
public static void main(String [] args) throws IOException
{
File file = new File("F://JAVA//11//splitfile");
HeBingFile(file);
}
public static void HeBingFile(File file) throws IOException
{
//获取配置文件
File[] files = file.listFiles(new SuffixFilter(".Properties"));
if (files.length!=1)
{
throw new RuntimeException("配置文件不存在或不唯一");
}
File fie = files[0];
Properties pro = new Properties();
FileInputStream fis = new FileInputStream(fie);
pro.load(fis);
String filename = pro.getProperty("filename");
int time = Integer.parseInt(pro.getProperty("time"));
File[] filepart = file.listFiles(new SuffixFilter(".part"));
if (filepart.length!=(time-1))
{
throw new RuntimeException("获得的分割碎片不完整");
}
ArrayList<FileInputStream> al = new ArrayList<FileInputStream>();
for (int i = 1;i<time-1 ;i++ )
{
al.add(new FileInputStream(filepart[i]));
}
Enumeration<FileInputStream> en = Collections.enumeration(al);
SequenceInputStream sis = new SequenceInputStream(en);
FileOutputStream fos = new FileOutputStream(new File(file,filename));
byte[] by = new byte[1024];
int len = 0;
while ((len = sis.read(by))!=-1)
{
fos.write(by,0,len);
}
sis.close();
fos.close();
}
}
class SuffixFilter implements FilenameFilter
{
String ss;
SuffixFilter(String ss)
{
super();
this.ss = ss;
}
public boolean accept(File file,String name)
{
return name.endsWith(ss);
}
}
编译没错,运行说使用空参数!!!
--------------------编程问答--------------------
import java.io.*;
import java.util.Properties;
public class Test
{
private static final int SIZE = 1024*1024;
public static void main(String [] args) throws IOException
{
File file = new File("0.mp3");
SplitFile(file);
}
public static void SplitFile(File file) throws IOException
{
//获取文件
FileInputStream fis = new FileInputStream(file);
//用于存储文件分割信息
Properties pro = new Properties();
//将文件名保存
pro.setProperty("Filename",file.getName());
//定义一个缓冲区
byte[] by = new byte[SIZE];
int len = 0;
int cun = 1;
//指定分割碎片的存储目的
File dir = new File("F://JAVA//11//splitfile");
//判断文件夹是否存在,不存在则创建
if (!dir.exists())
{
dir.mkdirs();
}
FileOutputStream fos = null;
while ((len = fis.read(by))!= -1)
{
fos = new FileOutputStream(new File(dir,(cun++)+".part"));
fos.write(by,0,len);
fos.close();
}
//将存储分割信息学出
fos = new FileOutputStream(new File(dir,cun+".Properties"));
pro.setProperty("time",cun+"");
pro.store(fos,"");
fis.close();
}
}
这是分割器 --------------------编程问答-------------------- 自己定下,求大神帮忙看下 --------------------编程问答-------------------- 这句报错把
FileOutputStream fos = new FileOutputStream(new File(file,filename));
查了一下API
Throws:
NullPointerException - If child is null --------------------编程问答-------------------- 除 --------------------编程问答-------------------- filename == null
也就是属性文件里没有找到filename这个property的定义 --------------------编程问答--------------------
哦哦
--------------------编程问答--------------------
我知道这里报错
但是找不到原因 楼下的说了 我去查看下 --------------------编程问答--------------------
真的是这里错了
把大写写成小写去了 --------------------编程问答-------------------- 楼主你没有开发工具么 奥这么调试 --------------------编程问答--------------------
有啊 打开什么就用什么咯 没必要计较这么多 --------------------编程问答-------------------- 空指针的错对着源码看具体的行数哪个对象是null,然后再进行判断。 --------------------编程问答--------------------
谢谢 不过已经解决了
补充:Java , Java EE