Не пойму, почему задача не принимается. Хотя файл создаётся правильный. Где косяк?
package com.javarush.task.task18.task1827;
/*
Прайсы
*/
import java.io.*;
import java.util.ArrayList;
public class Solution {
public static void main(String[] args) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String fileName = reader.readLine();
reader.close();
String command = args[0];
String pn = args[1];
double price = Double.parseDouble(args[2]);
int quantity = Integer.parseInt(args[3]);
int maxId = 0;
String writeString;
ArrayList<String> list = new ArrayList<>();
String s = "";
FileInputStream fin = new FileInputStream(fileName);
while (fin.available() > 0) {
int i = fin.read();
if (i == 13) {
list.add(s);
s = "";
fin.read();
} else s = s + (char) i;
}
list.add(s);
fin.close();
String idString = list.get(list.size()-1);
if (idString.length() > 8) idString = idString.substring(0,8).trim();
maxId = Integer.parseInt(idString);
if (command.equals("-c")) {
writeString = getStringId(++maxId) + getStringPN(pn) + getStringPrice(price) + getStringQuantity(quantity);
FileOutputStream writer = new FileOutputStream(fileName);
for (String toWrite : list) {
writer.write(toWrite.getBytes());
writer.write(13);
writer.write(10);
}
writer.write(writeString.getBytes());
writer.close();
}
}
public static String getStringId (int id){
String s = Integer.toString(id);
while (s.length() < 8) s = s + " ";
if (s.length() > 8) s = s.substring(0,8);
return s;
}
public static String getStringPN (String pn){
String s = pn;
while (s.length() < 30) s = s + " ";
if (s.length() > 30) s = s.substring(0,30);
return s;
}
public static String getStringPrice (double price){
String s = Double.toString(price);
while (s.length() < 8) s = s + " ";
if (s.length() > 8) s = s.substring(0,8);
return s;
}
public static String getStringQuantity (int quantity){
String s = Integer.toString(quantity);
while (s.length() < 4) s = s + " ";
if (s.length() > 4) s = s.substring(0,4);
return s;
}
}