Прошу помочь мне разобраться , в чем моя ошибка?
Спасибо!!!
package com.javarush.task.task18.task1827;
/*
Прайсы
*/
import java.io.*;
import java.util.ArrayList;
import java.util.SplittableRandom;
public class Solution {
public static void main(String[] args) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String fileName = reader.readLine();
reader.close();
if (args[0].equals("-c")) {
String id = id(nextID(fileName));
String productName = productName(args[1]);
String price = price(Double.parseDouble(args[2]));
String quantity = quantity(Integer.parseInt(args[3]));
FileWriter writer = new FileWriter(fileName, true);
writer.write("\n" + id + productName + price + quantity);
writer.close();
}
}
public static int nextID (String fileName) throws IOException {
ArrayList<Integer> listID = new ArrayList<>();
BufferedReader reader = new BufferedReader(new FileReader(fileName));
while (true) {
String text = reader.readLine();
if (text == null) {
break;
}
else {
listID.add(Integer.parseInt(reader.readLine().substring(0, 8).trim()));
}
}
while(true) {
boolean check = true;
int buffer;
for (int i = 0; i < listID.size() - 1; i++) {
if (listID.get(i) > listID.get(i + 1)) {
check = false;
buffer = listID.get(i);
listID.set(i, listID.get(i + 1));
listID.set(i + 1, buffer);
}
}
if (check == true) {
break;
}
}
reader.close();
return listID.get(listID.size() - 1) + 1;
}
public static String id (int id) {
String textID = String.valueOf(id);
for (int i = textID.length(); i < 8; i++){
textID += " ";
}
return textID;
}
public static String productName (String productName) {
for (int i = productName.length(); i < 30; i++) {
productName += " ";
}
return productName;
}
public static String price (double price) {
String textPrice = String.valueOf(price);
for (int i = textPrice.length(); i < 8; i++) {
textPrice += " ";
}
return textPrice;
}
public static String quantity (int quantity) {
String textQuantity = String.valueOf(quantity);
for (int i = textQuantity.length(); i < 4; i++) {
textQuantity += " ";
}
return textQuantity;
}
}