Я поигрался на с данной программой на компе, все обновляет и удаляет, что не так?
package com.javarush.task.task18.task1828;
import java.io.*;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
/*
Прайсы 2
*/
public class Solution {
public static void main(String[] args) throws IOException {
ArrayList<String> lines = new ArrayList<>();
BufferedReader reader2 = new BufferedReader(new InputStreamReader(System.in));
ByteArrayOutputStream writer = new ByteArrayOutputStream();
String filePath = reader2.readLine();
try {
File file = new File(filePath);
FileReader fr = new FileReader(file);
BufferedReader reader = new BufferedReader(fr);
String line = reader.readLine();
while (line != null) {
lines.add(line);
line = reader.readLine();
}
reader.close();
reader2.close();
fr.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
if (args[0].equals("-u")) {
int change = 0;
for (int i = 0; i< lines.size();i++){
String []parts = lines.get(i).split(" ");
String id = parts[0];
if (args[1].equals(id)) {
change = (lines.indexOf(lines.get(i)));
String idn = lines.get(i).substring(0, 8);
String productName = lines.get(i).substring(8, 38);
String price = lines.get(i).substring(38, 46);
String quantity = lines.get(i).substring(46);
int idnLength = idn.length() - args[1].length();
String spaces = "";
for (int j = 0;j<idnLength;j++){
spaces += " ";
}
String idnResult = args[1] + spaces;
int productNameLength = productName.length() - args[2].length();
spaces = "";
for (int j = 0;j<productNameLength;j++){
spaces += " ";
}
String productNameResult = args[2] + spaces;
int priceLenth = price.length() - args[3].length();
spaces = "";
for (int j = 0;j<priceLenth;j++){
spaces += " ";
}
String priceResult = args[3] + spaces;
int quantityLength = quantity.length() - args[4].length();
spaces = "";
for (int j = 0;j<quantityLength;j++){
spaces += " ";
}
String quantityResult = args[4] + spaces;
lines.set(change, idnResult + productNameResult + priceResult + quantityResult);
}
}
} if (args[0].equals("-d")) {
int change = 0;
for (int i = 0; i< lines.size();i++){
String []parts = lines.get(i).split(" ");
String id = parts[0];
if (args[1].equals(id)) {
change = (lines.indexOf(lines.get(i)));
lines.remove(change);
}
}
}
try (FileWriter file1 = new FileWriter(filePath)) {
for (int i = 0; i < lines.size(); i++) {
file1.write(lines.get(i)+System.lineSeparator());
}
}
writer.close();
}
}