Не могу разобраться с задачей. Ни комменты, ни помощь, ни гугл не помогли. Осталась надежда только на опытных ветеранов.
package com.javarush.task.task18.task1828;
import java.util.*;
import java.io.*;
/*
Прайсы 2
*/
public class Solution {
public static void main(String[] args) throws Exception {
if (args.length != 0) {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String name = reader.readLine();
reader.close();
BufferedReader input = new BufferedReader(new FileReader(name));
FileOutputStream output = new FileOutputStream(name);
ArrayList<String> fileData = new ArrayList<>();
String line;
while ((line = input.readLine()) != null) {
fileData.add(line);
}
switch (args[0]) {
case ("-u"):
int id = Integer.parseInt(args[1]);
String productName = args[2];
double price = Double.parseDouble(args[3]);
int quantity = Integer.parseInt(args[4]);
String result = String.format("%n%-8d%-30.30s%-8.2f%-4d", id, productName, price, quantity);
for (String str : fileData) {
if ((str.substring(0, 8).trim()).equals(args[1])) {
fileData.set(fileData.indexOf(str), result);
}
break;
}
case ("-d"):
for (String str : fileData) {
if ((str.substring(0, 8).trim()).equals(args[1])) {
fileData.remove(fileData.indexOf(str));
}
break;
}
}
for (String str : fileData) {
output.write(str.getBytes());
output.write("\n".getBytes());
}
input.close();
output.close();
}
}
}