public static void segmentation(String src, String dir) {
try {
File file = new File(dir);
File f2 = new File(src);
FileInputStream stream = new FileInputStream(src);
int i = stream.available();
String name = f2.getName();
int Bytes_per_file = i % 5 != 0 ? i / 5 + 1 : i / 5;
byte[] bytes = new byte[Bytes_per_file];
int len = -1;
int count = 0;
if (file.isDirectory()) {
while ((len = stream.read(bytes)) != -1) {
FileOutputStream stream1 =
new FileOutputStream(dir + "\\" + name.substring(0, name.indexOf(".")) + (count++) + ".bat");
stream1.write(bytes, 0, len);
stream1.close();
}
} else {
file.mkdirs();
segmentation(src, dir);
}
stream.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
static String[] bats = new String[5];
public static String[] Flie(String s, String dir) {
File file = new File(s);
File[] files = file.listFiles();
int i = 0;
for (File f : files) {
if (f.isDirectory()) {
String name = f.getAbsolutePath();
Flie(name, dir);
} else if (f.isFile() && f.getName().endsWith(".bat")) {
String path = f.getAbsolutePath();
bats[i] = path;
i++;
}
}
FileSynthesis(bats, dir);
return bats;
}
public static void FileSynthesis(String[] s, String dir) {
long a = System.currentTimeMillis();
File file = new File(dir);
file.mkdirs();
file.delete();
try {
FileOutputStream ou = new FileOutputStream(dir, true);
for (int i = 0; i < s.length; i++) {
FileInputStream stream = new FileInputStream(s[i]);
byte[] bytes = stream.readAllBytes();
ou.write(bytes);
}
long b = System.currentTimeMillis();
System.out.println(b - a);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public static void FileSynthesis2(String[] s, String dir) {
ArrayList<Byte> bytes1 = new ArrayList<>();
File file = new File(dir);
file.mkdirs();
file.delete();
try {
for (int i = 0; i < s.length; i++) {
FileInputStream stream = new FileInputStream(s[i]);
byte[] bytes = stream.readAllBytes();
for (byte aByte : bytes) {
bytes1.add(aByte);
}
System.out.println(Arrays.toString(bytes));
}
FileOutputStream stream = new FileOutputStream(dir);
stream.write(bytes1.toString().getBytes(), 0, bytes1.size());
} catch (IOException e) {
throw new RuntimeException(e);
}
}