everything verifies but "When you run the program without arguments, the product list must remain unchanged"
package com.codegym.task.task18.task1827;
import jdk.nashorn.internal.ir.debug.ClassHistogramElement;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.util.ArrayList;
import java.io.File;
/*
Prices
*/
public class Solution {
public static void main(String[] args) throws Exception {
ArrayList<String> fileLines = new ArrayList<>();
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String fileName = reader.readLine();
reader.close();
BufferedReader reader2 = new BufferedReader(new FileReader(fileName));
while(true)
{
String line= reader2.readLine();
if(line == null)
{
break;
}
else
{
fileLines.add(line);
}
}
reader2.close();
String lastLine = fileLines.get(fileLines.size() -1);
int lastId = Integer.parseInt(lastLine.substring(0,8));
if(args[0]=="-c")
{
String productName = args[1];
String id = String.valueOf(lastId+1);
String price = String.valueOf(Double.parseDouble(args[2]));
String quantity = String.valueOf(Integer.parseInt(args[3]));
// String productOutput = String.format("|%8d|", id) + String.format("|%30s|", productName) + String.format("|%8f|",price)+ String.format("|%4d|", quantity);
while(id.length()<8)
{
id += " ";
}
while(productName.length()<30)
{
productName += " ";
}
while(price.length()<8)
{
price += " ";
}
while(quantity.length()<4)
{
quantity += " ";
}
byte[] bytes= (id+ productName+ price+ quantity).getBytes();
String lineSeparator = System.getProperty("line.separator");
FileOutputStream outputStream = new FileOutputStream(fileName, true);
outputStream.write(lineSeparator.getBytes());
File f = new File(fileName);
outputStream.write(bytes, (int) f.length(),bytes.length);
outputStream.close();
}
}
}