I think my code is just fine but there is something wrong with the verification. Or am I missing something?
package com.codegym.task.task18.task1825;
import java.io.*;
import java.util.Map;
import java.util.TreeMap;
/*
Building a file
*/
public class Solution {
public static void main(String[] args) throws IOException {
//TODO: The program must read file names from the console
// until the word "end" is entered.
//TODO: Create a stream to write to the file without the "part" suffix
// (".<partN>") in the folder with all the "part" files.
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
//create a map for all files
//Map<String, String> folders = new TreeMap<>();//places all the entries in order
Map<Integer, String> folder = new TreeMap<>();// place all entries in order ans parse the string pf number into an Integer
String s;
while (!(s = reader.readLine()).equals("end")) {
s = reader.readLine();//reads the filenames
//How to remove the .part* because then all the files will have the same name...
//split the filenames up into firstbit goes int as value and the bit with the .part<n> will go in the first String
String partNumber = s.substring(s.indexOf(".part"));//creates substring which starts from .part
String filename = s.substring(0, s.indexOf(".part"));//substring of the part till the .part<N>
// or remove also the word ".part"
String part = s.substring(s.indexOf(".part") + 5);
folder.put(Integer.parseInt(part), filename);
//folders.put(partNumber, filename);
}
reader.close();
BufferedWriter writer = new BufferedWriter(new FileWriter(new File("")));
for (Map.Entry<Integer, String> pair : folder.entrySet()) {
writer.write(pair.getValue());
}
writer.close();
}
}