import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws FileNotFoundException, IOException {
File sourceFile = new File("ping.mp3");
// System.out.println(sourceFile.exists());
Scanner scanner = new Scanner(System.in);
int numberOfPieces = 1; //默认文件切割的数量
System.out.println("Enter:"); //提示输入
numberOfPieces = scanner.nextInt(); //输入
scanner.close(); //输入后就关闭 装完逼就跑一个道理
long fileLength = sourceFile.length() / numberOfPieces; //分一下每一个小文件的大小
byte[] b = new byte[1024]; //这个不解释 如果看不懂 就去看IO流去吧
RandomAccessFile raf1 = new RandomAccessFile(sourceFile, "r");
int len = -1;
for(int i = 0; i < numberOfPieces; i++) {
String name = sourceFile.getName() + "." + (i+1);
File file = new File(name);
file.createNewFile();
RandomAccessFile raf2 = new RandomAccessFile(file, "rw");
while((len = raf1.read(b)) != -1) {
raf2.write(b, 0, len); //我觉的这样写比raf2.write(b);高明一些
if(raf2.length() > fileLength) //如果太大了就不在这个子文件写了 换下一个
break;
}
raf2.close();
}
raf1.close();
}
}
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
//文件合并 ping.n
public class Main {
public static void main(String[] args) throws FileNotFoundException, IOException {
File[] files = new File[10];
String name = "ping.";
File file = new File("ping.mp3");
file.createNewFile();
RandomAccessFile in = new RandomAccessFile(file, "rw");
in.setLength(0);
in.seek(0);
byte[] bytes = new byte[1024];
int len = -1;
for(int i = 0; i < files.length; i++) {
files[i] = new File(name + (i + 1));
//System.out.println(files[i].exists());
RandomAccessFile out = new RandomAccessFile(files[i], "rw");
while((len = out.read(bytes)) != -1) {
in.write(bytes, 0, len);
}
out.close();
}
in.close();
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有