В IDEA все работает как нужно.
package com.javarush.task.task18.task1825;
/*
Собираем файл
*/
import java.io.*;
import java.util.ArrayList;
/*
Собираем файл
*/
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader file = new BufferedReader(new InputStreamReader(System.in));
ArrayList<String> address = new ArrayList<>();
String ad = "";
while (true){
ad = file.readLine();
if (ad.equals("end")){
break;
}
else
address.add(ad);
}
String addressWrite = address.get(0).substring(0, (address.get(0).indexOf("Part")));
addressWrite = addressWrite+"txt";
FileOutputStream writ = new FileOutputStream(addressWrite);
for (int i = 0; i < address.size(); i++ ){
String index = String.valueOf(i+1);
if (address.get(i).indexOf(index) > 0){
FileInputStream read= new FileInputStream(address.get(i));
byte [] buffer = new byte [read.available()];
while (read.available() > 0){
read.read(buffer);
writ.write(buffer);
}
read.close();
}
}
writ.close();
}
}