Почему не понимаю, использую try с ресурсами, пишет что не закрыты потоки
при тестах файл корректно редактируется программой, но валидатор отказывается принимать
package com.javarush.task.task18.task1828;
/*
Прайсы 2
*/
import java.io.*;
import java.util.*;
public class Solution {
public static void main(String[] args) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String file = reader.readLine();
ArrayList<String> list = new ArrayList<>();
if (args.length == 5 && "-u".equals(args[0])) {
readFile(file, list);
int n = findData(args[1], list);
chek(args);
String injection = String.format("%-8s%-30s%-8s%-4s", args[1], args[2], args[3], args[4]);
//System.out.println("injection: " + injection);
list.set(n, injection);
fileWriter(file, list);
} else if (args.length == 2 && "-d".equals(args[0])) {
readFile(file, list);
int n = findData(args[1], list);
list.remove(n);
fileWriter(file, list);
}
}
public static void readFile(String file, List<String> list) throws Exception {
try (BufferedReader in = new BufferedReader(new FileReader(file))) {
String str = null;
while ((str = in.readLine()) != null) {
list.add(str);
}
}
}
public static int findData(String id, List<String> list) {
int n = 0;
//System.out.println("paramId: " + id);
for (int i = 0; i < list.size(); i++) {
String listId = list.get(i).substring(0, 8).trim();
//System.out.println("listid: " + listId);
if (id.equals(listId)){
n = i;
break;
}
}
return n;
}
public static void chek(String[] args) {
if (args[2].length() > 30) {
String newArgs2 = args[2].substring(0, 30);
args[2] = newArgs2;
}
if (args[3].length() > 8) {
String newArgs3 = args[3].substring(0, 8);
args[3] = newArgs3;
}
if (args[4].length() > 4) {
String newArgs4 = args[4].substring(0, 4);
args[4] = newArgs4;
}
}
public static void fileWriter(String file, List<String> list) throws Exception {
try (PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(file)))) {
for (String str :
list) {
out.println(str);
}
}
}
}