Хотя условие выполняется...
package com.javarush.task.task18.task1827;
import java.io.*;
import java.util.ArrayList;
import java.util.List;
/*
Прайсы
*/
public class Solution {
public static void main(String[] args) throws Exception {
BufferedReader bufread= new BufferedReader(new InputStreamReader(System.in));
StringBuilder id = strSetSpasec(8);
StringBuilder productName = strSetSpasec(30);
StringBuilder price = strSetSpasec(8);
StringBuilder quantity = strSetSpasec(4);
String path=bufread.readLine();
FileReader fileread=new FileReader(path);
BufferedReader bufreadfile=new BufferedReader(fileread);
String tt=null;
Integer Max=0;
List<String> txtfile=new ArrayList<String>();
while ((tt = bufreadfile.readLine())!=null && (!tt.isEmpty())) {
txtfile.add(tt);
Integer forid = getid(tt.substring(0, 7));
Max = Max > forid ? Max : forid;
}
bufread.close();
bufreadfile.close();
fileread.close();
FileWriter filewr=null;
try{
if(args[0].equals("-c")) {
filewr = new FileWriter(path, true);
setproduct(id, (++Max).toString());
setproduct(productName, args[1]);
setproduct(price, args[2]);
setproduct(quantity, args[3]);
filewr.write(id.toString() + productName.toString() +
price.toString() + quantity.toString()+"\r\n");
filewr.close();
}
}
catch(ArrayIndexOutOfBoundsException e){
return;
}
}
public static StringBuilder strSetSpasec(int capacity){
StringBuilder temp=new StringBuilder(0);
for(int i=0;i<capacity;i++)
temp.append(' ');
return temp;
}
public static Integer getid(String parce){
Integer id=null;
String idstr="";
for(int i=0;i<parce.length();i++){
char ch=parce.charAt(i);
if(ch==' ')
continue;
else
idstr+=ch;
}
id=Integer.parseInt(idstr);
return id;
}
public static StringBuilder setproduct(StringBuilder tmp, String str){
for(int i=0;i<str.length();i++){
if(i==(tmp.length()))
break;
tmp.setCharAt(i,str.charAt(i));
}
return tmp;
}
}