filePieceSize = 1024*1024*64;
}
将路径转换为文件对象,再计算将分割多少块:
File file = filePath.toFile();
int howManyParts = (int) Math.ceil(file.length() / (double)filePieceSize);
初始化输入输出流,出错输出错误信息,返回false,获得当前目录:
DataInputStream fileReader = null;
try {
fileReader = new DataInputStream(new FileInputStream(file));
} catch (FileNotFoundException e) {
e.printStackTrace();
System.out.println("文件找不到!");
return false;
}
DataOutputStream fileWriter;
Path dir = filePath.getParent();
接下来读取文件,并且分别输出到各个part文件中:
int readLength = -1;
long total = 0;
try {
for (int i = 1; i <= howManyParts ; i++){