Struggling to validate part3. It seems to work, only wont pass validation. Any insight welcome. tks
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 {
TreeMap<Integer,String> sortedMap = new TreeMap();
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String filename = "";
String root = "";
String[] tokens = null;
while (!(filename = reader.readLine()).equals("end")) {
tokens = filename.split("\\.(?=[^.]+$)");
root = tokens[0];
int count = Integer.parseInt(tokens[1].replaceAll("part", ""));
sortedMap.put(count, filename);
}
File outputFile = new File(root);
Iterator<Integer> iterator = sortedMap.keySet().iterator();
BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(outputFile));
while (iterator.hasNext()) {
Integer key = iterator.next();
File file = new File(sortedMap.get(key));
BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream(file));
int nRead=0;
while ((nRead = bufferedInputStream.read()) != -1) {
bufferedOutputStream.write(nRead);
}
bufferedInputStream.close();
}
bufferedOutputStream.close();
}
}