Проверку проходит, записывает верно, но где то проблема
package com.javarush.task.task18.task1827;
/*
Прайсы
*/
import java.io.*;
public class Solution {
public static void main(String[] args) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String fileName = reader.readLine();
int maxID = 0;
BufferedReader fileReader = null;
fileReader = new BufferedReader(new InputStreamReader(new FileInputStream(fileName)));
maxID = 0;
while (fileReader.ready()) {
String someString = fileReader.readLine();
if (!someString.equals("")) {
String[] splittedString = someString.split(" ");
if (Integer.parseInt(splittedString[0]) > maxID) maxID = Integer.parseInt(splittedString[0]);
}
}
if (args.length != 0) {
if ((args[0].equals("-c"))) {
String productName = args[1];
double price = Double.parseDouble(args[2]);
int quantity = Integer.parseInt(args[3]);
int id = ++maxID;
String fullString = String.format("%n%-8d%-30.30s%-8.2f%-4d", id, productName, price, quantity);
byte[] buffer = fullString.getBytes();
OutputStream outputStream = new FileOutputStream(fileName, true);
outputStream.write(buffer);
outputStream.flush();
outputStream.close();
}
}
fileReader.close();
reader.close();
}
}