拆分文件的方法
import java.io.*;
import java.util.*;
public class Exercise17_10 {
public static void main(String[] args) throws Exception{
Scanner sc = new Scanner(System.in);
ArrayList array = new ArrayList<>();
System.out.print("输入文件路径:");
String filename = sc.nextLine();//输入文件路径
File file = new File(filename);
split(file); //拆分方法
}
public static void split(File file){
byte[] data = new byte[(int)file.length()];
try{
FileInputStream re = new FileInputStream(file);//读取
re.read(data);
re.close();
}catch (FileNotFoundException ex){
ex.printStackTrace();
}catch (IOException ex){
ex.printStackTrace();
}
System.out.println(data.length / 1024 + "k");//原文件大小
int len = 1024;
int n = (int)(file.length() / len);//拆分后子文件个数,大小均为1kb
File[] file1 = new File[n + 1];
for(int i=0;i



