В файл пишет согласно условиям, но валидацию не проходит. Подскажите в чем причина.
package com.javarush.task.task18.task1827;
import java.io.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/*
Прайсы
*/
public class Solution {
public static void main(String[] args) throws Exception {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
String name = bufferedReader.readLine();
bufferedReader.close();
if (args.length == 0){
return;
}
if (args[0].equals("–c")) {
String path = name.split(" ")[0];
BufferedReader bf = new BufferedReader(new FileReader(path));
ArrayList<Integer> array = new ArrayList<>();
while (bf.ready()) {
String s = bf.readLine();
String s1 = s.substring(0, 8).trim();
array.add(Integer.parseInt(s1));
}
bf.close();
int max = Collections.max(array);
String id = String.valueOf(max + 1);
int idLen = id.length();
if(idLen < 8){
while (idLen<8){
id = id + " ";
idLen = id.length();
}
}
String productName = "";
for (int i =1; i<args.length-2;i++){
productName = productName + args[i] +" ";
}
productName.trim();
int productNameLen = productName.length();
if (productNameLen != 30) {
if (productNameLen < 30) {
while (productNameLen < 30) {
productName += " ";
productNameLen = productName.length();
}
} else {
productName = productName.substring(0, 30);
}
}
String price = args[args.length-2].trim();
int priceLen = price.length();
if (priceLen != 8) {
if (priceLen < 8) {
while (priceLen < 8) {
price += " ";
priceLen =price.length();
}
} else {
price = price.substring(0, 8);
}
}
String quantity = args[args.length-1].trim();
int quantityLen = quantity.length();
if (quantityLen != 4) {
if (quantityLen < 4) {
while (quantityLen < 4) {
quantity += " ";
quantityLen = quantity.length();
}
} else {
quantity = quantity.substring(0, 4);
}
}
String str = id + productName + price + quantity;
FileWriter fos = new FileWriter(path, true);
fos.write(str);
fos.close();
}
}
}