I feel that the problem validation is very poorly designed.
I get the output when I execute but fails validation. Can't spend any more hours. Some one please help me here.
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 {
Scanner scanner = new Scanner(System.in);
String file;
List<String> filenames = new ArrayList<>();
while (true){
file = scanner.nextLine();
if (file.equals("end")){
break;
} else {
filenames.add(file);
}
}
String originalFile = filenames.get(0);
originalFile = originalFile.replaceAll("\\.part[0-9]+", "");
BufferedOutputStream bfo = new BufferedOutputStream(new FileOutputStream(originalFile,true));;
List<Integer> partNumbers = new ArrayList<>();
for (String filename : filenames){
partNumbers.add(Integer.parseInt(filename.replaceAll(".*Lion\\.avi\\.part", "")));
}
Collections.sort(partNumbers);
for (Integer partNumber : partNumbers){
String partFile = originalFile + ".part" + partNumber;
BufferedInputStream bf = new BufferedInputStream(new FileInputStream(partFile));
byte[] buffer = new byte[bf.available()];
byte read;
while ((read = (byte)bf.read(buffer, 0, buffer.length)) > 0)
{
bfo.write(buffer, 0, read);
}
bf.close();
}
bfo.close();
}
}