Посмотрел много обсуждений данной задачи, добавил/исправил некоторые моменты, но задача все равно не проходит.
package com.javarush.task.task18.task1827;
/*
Прайсы
*/
import java.io.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Solution {
public static void main(String[] args) throws Exception {
String strId = null;
int nId;
if (args.length == 4) {
if (args[0].equals("-c") && args[1].length() > 0 && args[2].length() > 0 && args[3].length() > 0) {
try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
String path = reader.readLine();
Pattern id = Pattern.compile("\\d{1,8}");
try (BufferedReader fin = new BufferedReader(new FileReader(path))) {
while (fin.ready()) {
String content = fin.readLine();
Matcher matcherId = id.matcher(content);
if (matcherId.find()) strId = content.substring(matcherId.start(), matcherId.end());
}
}
try (FileWriter fout = new FileWriter(path, true)) {
if (strId == null) nId = 0;
else nId = Integer.parseInt(strId);
if (nId < 99_999_999)
fout.write(String.format("%-8.8s%-30.30s%-8.8s%-4.4s\n", ++nId, args[1], args[2], args[3]));
}
}
}
}
}
}