Валя говорит:
Создай поток для записи в файл без суффикса [.partN] в папке, где находятся все считанные файлы.
В новый файл перепиши все байты из файлов-частей *.partN.
Чтение и запись должны происходить с использованием буфера.
Созданные для файлов потоки должны быть закрыты.
Последнее мне нравится больше всего)))
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
SortedMap<Integer,String> map = new TreeMap<>();
while (true) {
String filename = reader.readLine();
if (filename.equals("end")) {
break;
} else {
try {
String[] idList = filename.split("\\.");
int id = Integer.parseInt(idList[idList.length-1].substring(5));
map.put(id,filename);
} catch (NumberFormatException e) {System.out.println("Impossible to parse this string");}
}
}
FileOutputStream foS = new FileOutputStream("/Users/nk/Documents/JAVA/partN/writer.txt",true);
for (Map.Entry<Integer,String> pair : map.entrySet()) {
FileInputStream fiS = new FileInputStream(pair.getValue());
byte[] buff = new byte[fiS.available()];
while (fiS.available() > 0) {
int count = fiS.read(buff);
}
foS.write(buff);
fiS.close();
}
reader.close();
foS.close();
}
}package com.javarush.task.task18.task1825;
import java.io.*;
import java.util.*;
/*
Собираем файл
*/
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
SortedMap<Integer,String> map = new TreeMap<>();
while (true) {
String filename = reader.readLine();
if (filename.equals("end")) {
break;
} else {
try {
String[] idList = filename.split("\\.");
int id = Integer.parseInt(idList[idList.length-1].substring(4));
map.put(id,filename);
} catch (NumberFormatException e) {System.out.println("Impossible to parse this string");}
}
}
for (Map.Entry<Integer,String> pair : map.entrySet()) {
FileOutputStream foS = new FileOutputStream("/Users/nk/Documents/JAVA/partN/writer.txt",true);
FileInputStream fiS = new FileInputStream(pair.getValue());
byte[] buff = new byte[fiS.available()];
while (fiS.available() > 0) {
int count = fiS.read(buff);
}
foS.write(buff);
fiS.close();
foS.close();
}
reader.close();
}
}