Считывание файлов проходит привильно и в правильном порядке. Но постоянно вылазет 4 ошибки и если ищо разкоментировать это строчку, то вийдет потенциально опасная операцыя:
Files.createFile(destination);
package com.javarush.task.task18.task1825;
import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*;
/*
Собираем файл
*/
public class Solution {
public static void main(String[] args) throws IOException {
Path destination = null;
Set<Path> parts = new TreeSet<>(Comparator.comparingInt(p -> Integer.parseInt(p.getFileName().toString().split("part")[1])));
try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
String s;
while (!(s = reader.readLine()).equals("end")) {
if (destination == null)
destination = Paths.get(Paths.get(s).getParent().toString() + "/" + s.substring(0, s.indexOf(".part")));
parts.add(Paths.get(s));
}
} catch (IOException e) {
e.printStackTrace();
}
if (destination == null) return;
Files.createFile(destination);
List<InputStream> inputs = new ArrayList<>();
for (Path p : parts)
inputs.add(new FileInputStream(p.toFile()));
OutputStream out = new FileOutputStream(destination.toFile());
for (InputStream in : inputs) {
byte[] b = new byte[in.available()];
while (in.available() > 0) {
int read = in.read(b);
out.write(b, 0, read);
}
in.close();
}
out.close();
}
}