все работает, но почему-то проверку не проходит.
package com.javarush.task.task18.task1825;
/*
Собираем файл
*/
import java.io.*;
import java.util.ArrayList;
import java.util.Collections;
public class Solution {
public static void main(String[] args) {
ArrayList<String> files = new ArrayList<>();
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String fileName;
FileInputStream fis = null;
BufferedInputStream bis = null;
FileOutputStream fos = null;
BufferedOutputStream bos = null;
try {
fos = new FileOutputStream("d:/test/1.txt", true);
bos = new BufferedOutputStream(fos);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
//заполняем лист files именами файлов.
try {
while (!(fileName = reader.readLine()).equals("end"))
files.add(fileName);
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
//создаем 2 листа для INT и для STRING
ArrayList<Integer> intArr = new ArrayList<>();
ArrayList<String> tmpStr = new ArrayList<>();
//добавляем в лист intArr число после PART
for(String a: files) {
intArr.add(Integer.parseInt(a.substring(a.lastIndexOf("t") + 1)));
}
//сортируем
Collections.sort(intArr);
//System.out.println(intArr);
//добавляем в лист tmpArr имена файлов в нужном порядке
for(int i: intArr) {
for (String a : files)
if (i == Integer.parseInt(a.substring(a.lastIndexOf("t") + 1)))
tmpStr.add(a);
}
//System.out.println(tmpStr);
//считываем имена файлов из tmpArr и записываем в файл 1.txt
while(!tmpStr.isEmpty()) {
try {
fis = new FileInputStream(tmpStr.get(0));
bis = new BufferedInputStream(fis);
byte[] byteArr = new byte[bis.available()];
while (bis.available() > 0) {
bis.read(byteArr);
}
bos.write(byteArr);
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
fis.close();
bis.close();
}catch (IOException e) {
e.printStackTrace();
}
}
tmpStr.remove(0);
if (tmpStr.isEmpty()) {
try {
//fos.close();
bos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}