import java.io.*;
public class Solution {
public static void main(String[] args) throws Exception {
// args[0] = -c
// args{1] = productName
// args[2] = price
// args[3] = quantity
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String s = reader.readLine();
reader.close();
if (args[0].equals("-c")) {
BufferedWriter bw = new BufferedWriter(new FileWriter(s,true));
String arg1 = args[1].length()>30 ? args[1].substring(0,30) : args[1];
String arg2 = args[2].length()>8 ? args[2].substring(0,8) : args[2];
String arg3 = args[3].length()>4 ? args[3].substring(0,4) : args[3];
String id = String.valueOf(id(s)) ;
if (id.length() > 8){// ВалидатораРотНаоборот}
String ss = String.format("%-8s%-30s%-8s%-4s", id, arg1, arg2, arg3);
bw.write(ss);
bw.close();
}
}}
public static int id(String args) throws Exception{
BufferedReader br = new BufferedReader(new FileReader(args));
int max = 0; //Integer.valueOf(((br.readLine()).substring(0,8)).trim()) это тоже не то
String s ;
while ((s=br.readLine()) != null){
int i =Integer.valueOf((s.substring(0,8)).trim());
if (max < i){
max = i;
}
}
br.close();
max=max+1;
return max ;
}
}
package com.javarush.task.task18.task1827;
/*
Прайсы
*/
import java.io.*;
public class Solution {
public static void main(String[] args) throws Exception {
// args[0] = -c
// args{1] = productName
// args[2] = price
// args[3] = quantity
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String s = reader.readLine();
reader.close();
if (args[0].equals("-c")) {
BufferedWriter bw = new BufferedWriter(new FileWriter(s,true));
String arg1 = args[1].length()>30 ? args[1].substring(0,30) : args[1];
String arg2 = args[2].length()>8 ? args[2].substring(0,8) : args[2];
String arg3 = args[3].length()>4 ? args[3].substring(0,4) : args[3];
String id = String.valueOf(id(s)) ;
if (id.length() > 8){// ебанутый валидатор, что тебе нужно}
String ss = String.format("%-8s%-30s%-8s%-4s", id, arg1, arg2, arg3);
bw.write(ss);
bw.close();
}
}}
public static int id(String args) throws Exception{
BufferedReader br = new BufferedReader(new FileReader(args));
int max = 0;
String s ;
while ((s=br.readLine()) != null){
int i =Integer.valueOf((s.substring(0,8)).trim());
if (max < i){
max = i;
}
}
br.close();
max=max+1;
return max ;
}
}