Коллеги, привет.
Прошу прокомментировать код и подсказать почему валидатор не пропускает?
Спасибо
package com.javarush.task.task18.task1825;
import java.awt.List;
import java.io.*;
import java.util.*;
/*
Собираем файл
*/
public class Solution {
public static void main(String[] args) throws IOException {
String folderName = "testFolder";
// File folder = new File("/home/pavel/JavaRushTasks/2.JavaCore/src/com/javarush/task/task18/task1825/"
// + folderName);
File folder = new File(folderName);
folder.mkdirs();
ArrayList<File> fileList = new ArrayList<>();
int n = 0;
while (true) {
n++;
String scannerString = new Scanner(System.in).nextLine();
if (scannerString.equals("end")) {
break;
}
String fileName = scannerString;
File file = new File(folder, fileName);
file.createNewFile();
String text = "1488text" + n;
FileOutputStream fosAddingText = new FileOutputStream(file);
BufferedOutputStream bosAddingText = new BufferedOutputStream(fosAddingText);
bosAddingText.write(text.getBytes());
fileList.add(file);
bosAddingText.flush();
bosAddingText.close();
fosAddingText.close();
}
File totalFile = new File(folder, "totalFile");
totalFile.createNewFile();
Map<Integer, File> numberAndFile = new TreeMap<>();
for (File files : fileList) {
String[] array = files.getName().toString().split(".part");
int numberInFile = Integer.parseInt(array[array.length - 1]);
numberAndFile.put(numberInFile, files);
}
FileInputStream fis = null;
BufferedInputStream bis = null;
FileOutputStream fos = new FileOutputStream(totalFile, true);
BufferedOutputStream bos = new BufferedOutputStream(fos);
byte[] buff = new byte[1024];
int bytes = 0;
for (Map.Entry e : numberAndFile.entrySet()) {
fis = new FileInputStream((File) e.getValue());
bis = new BufferedInputStream(fis);
bytes = bis.read(buff);
while (bytes != -1) {
bos.write(buff, 0, bytes);
bytes = bis.read(buff);
}
}
bos.flush();
bos.close();
fos.close();
fis.close();
bis.close();
}
}