I think I met all the requirements but obviously am misinterpreting something.
Tried debugging with cmd line input of single space between arguments and the 8 30 8 4 format and both add a line to the file that looks ok to me but the verification is none to happy.
package com.codegym.task.task18.task1827;
/*
Prices
*/
import java.io.*;
import java.util.*;
public class Solution {
public static void main(String[] args) {
try
{
if (args.length == 0) return;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String fileName = br.readLine();
FileReader fr = new FileReader(fileName);
BufferedReader brFile = new BufferedReader(fr);
Map<Integer, String> map = new TreeMap<>();
String line = null;
int id = 0;
while ((line = brFile.readLine()) != null)
{
id = Integer.parseInt(line.substring(0, 8).trim());
map.put(id, line);
}
if (args[0].equals("-c"))
{
id++;
Vector<String> vector = new Vector();
vector.addAll(Arrays.asList(args));
vector.remove(0); // -c action
Double price = Double.valueOf(vector.remove(vector.size()-1));
int quantity = Integer.valueOf(vector.remove(vector.size()-1));
String[] strings = vector.toArray(new String[vector.size()]);
String productName = String.join(" ", strings);
String create = String.format("%-8d%-30s%-8.2f%-4d", id, productName, price, quantity);
map.put(id, create);
}
int i = 0;
FileOutputStream fos = new FileOutputStream(fileName);
for (Map.Entry<Integer, String> m : map.entrySet())
{
fos.write((String.format("%s%n", m.getValue())).getBytes());
}
br.close();
fr.close();
fos.close();
brFile.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}