Тестировал все нормально, все четыре строки, все на своем месте, а валидатор говорит что Товар с измененными данными должен находится на той же строке в файле. Заранее спасибо за помощь
package com.javarush.task.task18.task1828;
/*
Прайсы 2
*/
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));
String file = reader.readLine();
//String file = "D:\\Папочка\\Учеба\\test";
InputStream inputStream = new FileInputStream(file);
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
ArrayList<String> list = new ArrayList<>();
String s;
while ((s = bufferedReader.readLine()) != null) {
list.add(s);
}
if (args.length > 0) {
ArrayList<Integer> listId = new ArrayList<>();
for (String value : list) {
String s1 = value.substring(0, 8);
String[] s2 = s1.split("\\s");
listId.add(Integer.parseInt(s2[0]));
}
TreeMap<Integer, String> map = new TreeMap<>();
for (int a = 0; a < list.size(); a++) {
map.put(listId.get(a), list.get(a));
}
String id = args[1];
for (int a = args[1].length(); a < 8; a++) {
id += " ";
}
int id1 = Integer.parseInt(args[1]);
if (args.length == 2) {
map.remove(id1);
list.clear();
for (Map.Entry<Integer, String> pair : map.entrySet()) {
list.add(pair.getValue());
}
}
if (args.length > 2) {
String line = "";
String productName = args[2];
for (int a = args[2].length(); a < 30; a++) {
productName += " ";
}
String price = args[3];
for (int a = args[3].length(); a < 8; a++) {
price += " ";
}
String quantity = args[4];
for (int a = args[4].length(); a < 4; a++) {
quantity += " ";
}
line = id + productName + price + quantity;
for(Map.Entry<Integer, String> pair : map.entrySet()){
int key = pair.getKey();
if(id1 == key){
map.put(key, line);
}
}
list.clear();
for (Map.Entry<Integer, String> pair : map.entrySet()) {
list.add(pair.getValue());
}
}
PrintStream printStream = new PrintStream(new FileOutputStream(file));
for (String a : list) {
printStream.println(a);
}
reader.close();
inputStream.close();
bufferedReader.close();
printStream.close();
}
}
}