I've tested this successfully on my system and reviewed the other questions and responses.
I believe I'm doing it right, but obviously not.
My thoughts are that I'm not using the method(s) that it wants.
Help?
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 {
//get list of all the fileNames
List<String> fileList = getInput();
//sort list by part order
Collections.sort(fileList);
//get the fileName without "part" for output filename
String outputFileName = getOutputFileName(fileList.get(0));
FileInputStream inputStream;
FileOutputStream outputStream = new FileOutputStream(new File(outputFileName), true);
for (String name : fileList) {
inputStream = new FileInputStream(name);
byte[] buffer = new byte[1000];
while (inputStream.available() > 0) {
int dataLength = inputStream.read(buffer);
outputStream.write(buffer, 0, dataLength);
}
inputStream.close();
}
outputStream.close();
}
//input fileNames until "end" and add to list
private static List<String> getInput() {
List<String> fileList = new ArrayList<>();
Scanner scanner = new Scanner(System.in);
String fileName;
while (!(fileName = scanner.nextLine()).equals("end")) {
fileList.add(fileName);
}
scanner.close();
return fileList;
}
//returns the name of the file without "part"
private static String getOutputFileName(String fileName) {
//use the name to determine where "part" is in the fileName
String pathName = new File(fileName).getAbsolutePath();
String[] filePathArray = pathName.split("\\.");
StringBuilder sb = new StringBuilder();
for (int i = 0; i < filePathArray.length - 1; i++) {
sb.append(filePathArray[i]);
if (filePathArray[i + 1].startsWith("part")) {
break;
} else
sb.append(".");
}
return sb.toString();
}
}