Всем привет. Подскажите что не так.
package com.javarush.task.task18.task1827;
/*
Прайсы
*/
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
public class Solution {
public static void main(String[] args) throws Exception {
if (args.length> 0 && args[0].equals("-c")) {
int lenID = 8;
int lenproductName = 30;
int lenprice = 8;
int lequantity = 4;
String res = "\n";
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String productName = (args[1].length()<=30)?args[1]:args[1].substring(0,29);
float price = Float.parseFloat((args[2].length()<=8)?args[2]:args[2].substring(0,6));
int quantity = Integer.parseInt((args[3].length()<=4)?args[3]:args[3].substring(0,3));
String fileName = reader.readLine();
reader.close();
FileInputStream streamRead = new FileInputStream(fileName);
reader = new BufferedReader(new InputStreamReader(streamRead));
String str;
int maxID = 0;
while ((str = reader.readLine()) != null) {
int currID = Integer.parseInt(str.substring(0,7).replace(" ",""));
if (maxID < currID) maxID = currID;
}
maxID++;
reader.close();
res += maxID;
for(int i = String.valueOf(maxID).length(); i < lenID; i++) res = res+" ";
res += productName;
for(int i = productName.length(); i < lenproductName; i++) res = res+" ";
res += price;
for(int i = String.valueOf(price).length(); i < lenprice; i++) res = res+" ";
res += quantity;
for(int i = String.valueOf(quantity).length(); i < lequantity; i++) res = res+" ";
FileOutputStream streamWrite = new FileOutputStream(fileName, true);
streamWrite.write(res.getBytes());
streamWrite.close();
}
}
}