Битва с валидатором успешно проиграна. Код работает в соответствии с заданием
package com.javarush.task.task18.task1825;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/*
Собираем файл
*/
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String fileName = reader.readLine();
//List<String> fullNames = new ArrayList<>();
Map<Integer, String> fullNames = new TreeMap<>();
String indexSubstring = "";
int index = 0;
Pattern patternPath = Pattern.compile("part\\d+");
Matcher matcher = patternPath.matcher(fileName);
while (!fileName.equals("end")){
while (matcher.find()){
indexSubstring = fileName.substring(matcher.start());
Pattern patternIndex = Pattern.compile("\\d+");
Matcher matcherIndex = patternIndex.matcher(indexSubstring);
while (matcherIndex.find()){
index = Integer.parseInt(indexSubstring.substring(matcherIndex.start(), matcherIndex.end()));
}
fileName = fileName.substring(0, matcher.start()-1);
}
fullNames.put(index, fileName);
fileName = reader.readLine();
matcher = patternPath.matcher(fileName);
}
reader.close();
List<byte[]> byteBuff = new ArrayList<>();
for (Map.Entry<Integer, String> entry : fullNames.entrySet()){
FileInputStream fileInputStream = new FileInputStream(entry.getValue());
byte[] currentBuf = new byte[fileInputStream.available()];
fileInputStream.read(currentBuf);
byteBuff.add(currentBuf);
fileInputStream.close();
}
FileOutputStream fileOutputStream = new FileOutputStream(fullNames.get(1), true);
for (byte[] Buf : byteBuff){
fileOutputStream.write(Buf);
}
fileOutputStream.close();
}
}