I'm missing something again...
package com.codegym.task.task18.task1825;
import java.io.*;
import java.util.*;
/*
Building a file
*/
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader (new InputStreamReader(System.in));
String locationName = "path\\desktop\\folder";
String fileName = "";
String pathAndFileName = "";
String backUpFileName = "";
ArrayList<String> files = new ArrayList<>();
while(true){
fileName = reader.readLine();
if(fileName.equals("end")){
break;
}
backUpFileName = fileName; //so fileName is not "end"
pathAndFileName = locationName + fileName;
files.add(pathAndFileName);
}
reader.close();
Collections.sort(files);
String nameFileforAllParts = locationName;
String[] everyWordOfFileName = backUpFileName.split("\\.");
for(String s : everyWordOfFileName){
if(s.startsWith("part")){
break;
}
nameFileforAllParts = nameFileforAllParts + s + ".";
}
nameFileforAllParts = nameFileforAllParts + "txt";
File allParts = new File(nameFileforAllParts);
FileOutputStream fos = new FileOutputStream(allParts);
for(String s : files){
FileInputStream fis = new FileInputStream(s);
while(fis.available() > 0){
int count = fis.read();
fos.write(count);
}
fis.close();
}
fos.close();
}
}