Any help would be great.
package com.codegym.task.task18.task1827;
/*
Prices
*/
import java.io.*;
import java.util.ArrayList;
import java.util.Collections;
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();
ArrayList<String> idList = new ArrayList<>();
// String argument1 = "-c";
// String argument2 = "something has to be done thd";
// String argument3 = "34.3";
// String argument4 = "342";
// String fileName = "C:/Users/Dan/Desktop/idFile1.txt";
BufferedReader bufferedReader = new BufferedReader(new FileReader(fileName));
while (bufferedReader.ready()) {
String idLine = bufferedReader.readLine().substring(0, 8);
StringBuffer id = new StringBuffer();
for (int i = 0; i < idLine.length(); i++) {
if (!Character.isWhitespace(idLine.charAt(i)))
id.append(idLine.charAt(i));
}
idList.add(String.valueOf(id)); //adding all ids to the list
}
bufferedReader.close();
Collections.sort(idList); // sorting the ids
System.out.println(idList.toString());
//
// //creating a new ID
int intId = Integer.parseInt((idList.get(idList.size() - 1))) + 1;
String stringId = String.valueOf(intId);
while (stringId.length() < 8) {
stringId += " ";
}
System.out.println(stringId);
//
// //setting product characters length
String productName = args[1];
while (productName.length() < 30) {
productName += " ";
}
System.out.println(productName);
// // setting price length
String price = args[2];
while (price.length() < 8) {
price += " ";
}
System.out.println(price);
// //setting quantity length
String quantity = args[3];
while (quantity.length() < 4) {
quantity += " ";
}
// System.out.println(quantity);
//
String productToAdd = stringId + productName + price + quantity;
// System.out.println(productToAdd);
if (args[0] != null) {
FileInputStream inputStream = new FileInputStream(fileName);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
while (inputStream.available() > 0) {
byteArrayOutputStream.write(inputStream.read());
}
inputStream.close();
FileOutputStream outputStream = new FileOutputStream(fileName);
byteArrayOutputStream.writeTo(outputStream);
outputStream.write("\n".getBytes());
outputStream.write(productToAdd.getBytes());
outputStream.close();
byteArrayOutputStream.close();
}
}
}