Прошу помогите, че ему не нравится? (игнорьте последние 12 строк комментов)
package com.javarush.task.task18.task1825;
import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.*;
/*
Собираем файл
*/
public class Solution {
public static void main(String[] args) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
Scanner scanner = new Scanner(reader);
String fileName = scanner.nextLine();
Map<Integer, String> fileNames = new TreeMap<Integer, String>();
while (!fileName.equals("end")) {
fileNames.put(parsePartNumber(fileName), fileName);
fileName = scanner.nextLine();
}
reader.close();
String newFileName = fileNames.get(1).replace(".part1", "");
File newFile = new File(newFileName);
newFile.createNewFile(); // создаем файл для объединения
fileNames.values().forEach(part -> {
try {
writePart(part, newFileName);
} catch (Exception e) {
e.printStackTrace();
}
});
}
public static int parsePartNumber(String fileName) {
String[] substrings = fileName.split("\\.");
String substrWithNumber = substrings[substrings.length - 1];
return Integer.parseInt(substrWithNumber.replace("part", ""));
}
public static void writePart(String source, String destination) throws Exception {
try (BufferedInputStream input = new BufferedInputStream(new FileInputStream(source));
BufferedOutputStream output = new BufferedOutputStream(new FileOutputStream(destination, true))) {
byte[] inputBytes = new byte[input.available()];
input.read(inputBytes);
output.write(inputBytes);
}
}
// public static String nextLine(BufferedInputStream reader) throws Exception{
// int readByte;
// char c;
// StringBuilder fileNameSB = new StringBuilder("");
// while ((readByte = reader.read()) != -1) {
// c = (char) readByte;
// fileNameSB.append(c);
// }
// System.out.println(fileNameSB);
// return fileNameSB.toString();
// }
}