Программа работает но что то не так. Потоки закрыты Но.....
package com.javarush.task.task18.task1827;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
/*
Прайсы
*/
public class Solution {
public static void main(String[] args) throws Exception {
if (args[0].equals("-c") && args[1]!=null && args[2]!=null && args[3]!=null){
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
String filePath = input.readLine();
FileReader fileIn = new FileReader(filePath);
ArrayList<Integer> listId = new ArrayList<>();
char[] chars = new char[52];
int count;
while ((count = fileIn.read(chars)) !=-1){
String stAll = new String(chars,0,count);
String subStId = stAll.substring(0,8);
String stID = new String(subStId.getBytes(),0,subStId.length(),"UTF-8");
stID = stID.replaceAll(" ","");
listId.add(Integer.parseInt(stID));
}
fileIn.close();
String stId = String.valueOf(Collections.max(listId)+1);
while (true){
if (stId.length()<8){
stId += " ";
} else {
break;
}
}
while (true){
if (args[1].length()<30){
args[1] += " ";
} else {
break;
}
}
while (true){
if (args[2].length()<8){
args[2] += " ";
} else {
break;
}
}
while (true){
if (args[3].length()<4){
args[3] += " ";
} else {
break;
}
}
FileWriter fileOut = new FileWriter(filePath,true);
fileOut.write("\r\n",0,2);
fileOut.write(stId,0,8);
fileOut.write(args[1],0,30);
fileOut.write(args[2],0,8);
fileOut.write(args[3],0,4);
fileOut.close();
}
}
}