I have been tested with different path and folders - all ok!
package com.codegym.task.task18.task1825;
import java.io.*;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/*
Building a file
*/
public class Solution {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
ArrayList<File> ar = new ArrayList<>();
while (true) {
String s = sc.nextLine();
if (s.equals("end")) break;
File f = new File(s);
ar.add(f);
}
sc.close();
Collections.sort(ar);
Path p = Paths.get(ar.get(0).getAbsolutePath());
String fname = String.valueOf(p.getFileName());
String[] sa = fname.split("\\.part\\d+");
File test = new File(String.valueOf(p));
FileOutputStream results = new FileOutputStream(p.getParent() + "\\" + sa[0] + "." + getFileExtension(test));
for (File d : ar) {
FileInputStream i = new FileInputStream(d);
while (i.available()>0) {
int data = i.read();
results.write(data);
}
i.close();
}
results.close();
}
public static String getFileExtension(File file) {
String fileName = file.getName();
if (fileName.lastIndexOf(".") != -1 && fileName.lastIndexOf(".") != 0)
return fileName.substring(fileName.lastIndexOf(".")+1);
else return "";
}
}