/**
- Объединение файлов
-
- @param file
- @param folder
- @param filename
/
public static String merge(String file, String folder, String filename) {
// По умолчанию объединение выполнено успешно
String rlt = "200";
try {
// Сначала проверяем, существует ли файл
if (fileExists(file)) {
// Файл уже существует
rlt = "300";
} else {
// Если файла нет, выполняем объединение
File dir = new File(folder);
if (!dir.exists()) {
dir.mkdir();
}
File thefile = new File(file);
if (!thefile.exists()) {
thefile.createNewFile();
}
int index = 0;
boolean isExist = false;
do {
index = index + 1;
File chunkFile = new File(file + "" + index);
if (chunkFile.exists()) {
isExist = true;
Files.write(Paths.get(file), Files.readAllBytes(Paths.get(file + "" + index)), StandardOpenOption.APPEND);
// После объединения удаляем файл-часть
chunkFile.delete();
} else {
isExist = false;
break;
}
} while (isExist);
/ Files.createFile(Paths.get(file));
Stream f1 = Files.list(Paths.get(folder));
Stream f2 = f1.filter(path -> !path.getFileName().toString().equals(filename));
Stream f3 = f2.sorted((o1, o2) -> {
String p1 = o1.getFileName().toString();
String p2 = o2.getFileName().toString();
int i1 = p1.lastIndexOf("");
int i2 = p2.lastIndexOf("");
String emp1 = p1.substring(i1);
emp1 = emp1.replace("", "");
String emp2 = p2.substring(i2);
emp2 = emp2.replace("", "");
return Integer.valueOf(emp2).compareTo(Integer.valueOf(emp1));
});
*/
}
}```java
f3.forEach(path -> {
try {
//Запись в файл в режиме добавления
Files.write(Paths.get(file), Files.readAllBytes(path), StandardOpenOption.APPEND);
//После объединения удалить этот блок
Files.delete(path);
} catch (IOException e) {
logger.error(e.getMessage(), e);
}
});
}
} catch (IOException e) {
logger.error(e.getMessage(), e);
//Объединение не удалось
rlt = "400";
}
return rlt;
}
Вот исправленный текст с переводом описательных фраз на русский язык. Форматирование и структура оригинального кода сохранены.