...
package com.javarush.task.task18.task1828;
/*
Прайсы 2
*/
import java.io.*;
import java.util.ArrayList;
import java.util.Formatter;
public class Solution {
public static void main(String[] args) throws IOException {
if (args.length > 0) {
BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
String nameCrUD = r.readLine();
r.close();
String id = "";
String productName = "";
String price = "";
String quantity = "";
if (args.length > 2) {
id = String.format("%-8s", args[1]);
productName = String.format("%-30s", args[2]);
price = String.format("%-8s", args[3]);
quantity = String.format("%-4s", args[4]);
} else {
id = String.format("%-8s", args[1]);
}
ArrayList<String> arrayList = new ArrayList<>();
BufferedReader r1 = new BufferedReader(new FileReader(nameCrUD));
String text = r1.readLine();
while (text != null) {
if (text.contains(id)) {
String text2 = text.substring(0, 8).trim();
String[] text3 = text2.split(" ");
if (text3[0].equals(id) && args[0].equals("-u")) {
arrayList.add(id + productName + price + quantity);
} else if (text3[0].equals(id) && args[0].equals("-d")) {
}
} else {
arrayList.add(text);
}
text = r1.readLine();
}
r1.close();
BufferedWriter bw = new BufferedWriter(new FileWriter(nameCrUD));
for (int i = 0; i < arrayList.size(); i++) {
bw.write(arrayList.get(i) + "\n");
}
bw.close();
}
}
}