Танцы с бубном и пробелами вокруг валидатора....И в конец строки пробелы добавлял, и в начало для price и quantity... Что в итоге то нужно, так и не понял (
package com.javarush.task.task18.task1827;
import java.io.*;
import java.lang.*;
/*
Прайсы
*/
public class Solution {
public static void main(String[] args) throws Exception {
if (args.length ==4 && args[0].equals("-c")) {
BufferedReader sc = new BufferedReader(new InputStreamReader(System.in));
String filename = sc.readLine();
sc.close();
BufferedReader freader = new BufferedReader(new FileReader(filename));
String line = null;
int max = 0, id = 0;
while ((line = freader.readLine()) != null) {
id = Integer.parseInt(line.substring(0,8).trim());
max = max > id ? max : id;
}
freader.close();
id = max+1;
StringBuilder sb = new StringBuilder();
sb.append('\n').append(getStrFormat(Integer.toString(id), 8)).append(getStrFormat(args[1],30)).append(getS(args[2],8)).append(getS(args[3],4));
System.out.println(sb.toString());
FileOutputStream out = new FileOutputStream(filename, true);
out.write(sb.toString().getBytes());
out.close();
}
}
public static String getStrFormat(String s, int len) {
if(s.length() < len) {
for(int i = s.length(); i < len; i++) {s.concat(" ");}
} else if(s.length() > len) {
s = s.substring(0,len);
}
return s;
}
public static String getS(String s, int len) {
if(s.length() < len) {
for(int i = s.length(); i < len; i++) {s=" " + s;}
} else if(s.length() > len) {
s = s.substring(0,len);
}
return s;
}
}