again with my files, everything's fine...... please help as this is the only impediment from me getting all tasks from this level done achievement.......
package com.codegym.task.task18.task1828;
/*
Prices 2
*/
import java.io.*;
import java.util.ArrayList;
public class Solution {
public static void main(String[] args) throws IOException {
//args = new String[] {"-u", "1234", "feina freakinhjhjhj", "12.89", "234"};
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String fileName = reader.readLine();
reader.close();
BufferedReader reader2 = new BufferedReader(new FileReader(fileName));
ArrayList<String> strings = new ArrayList<>();
while (true) {
String line = reader2.readLine();
if (line == null) {
break;
}
strings.add(line);
}
reader2.close();
if (args[0].equals("-d")) {
for (int i = 0; i < strings.size(); i++) {
if (args[1].equals(strings.get(i).substring(0, 8).replaceAll(" ", ""))) {
strings.remove(i);
break;
}
}
FileOutputStream outputStream = new FileOutputStream(fileName);
for (String s: strings
) {
outputStream.write(s.getBytes());
outputStream.write(System.lineSeparator().getBytes());
}
outputStream.close();
}
if (args[0].equals("-u")) {
String id = args[1];
String productName = args[2];
String price = String.valueOf(Double.parseDouble(args[3]));
String quantity = String.valueOf(Integer.parseInt(args[4]));
while (productName.length() < 30) {
productName += " ";
}
while (price.length() < 8) {
price += " ";
}
while (quantity.length() < 4) {
quantity += " ";
}
String updatedString = productName + price + quantity;
for (int i = 0; i < strings.size(); i++) {
if (args[1].equals(strings.get(i).substring(0, 8).replaceAll(" ", ""))) {
while (id.length() < 8) {
id += " ";
}
strings.set(i, id + updatedString);
break;
}
}
FileOutputStream outputStream = new FileOutputStream(fileName);
for (String s: strings
) {
outputStream.write(s.getBytes());
outputStream.write(System.lineSeparator().getBytes());
}
outputStream.close();
}
}
}