Результат работы программы соответствует заданию . При попытке проверить задачу получаю ответ "Неизвестная ошибка". Подскажите, что не так в моем коде?)
package com.javarush.task.task18.task1827;
import java.io.*;
public class Product {
private byte [] id;
private byte [] productName;
private byte [] price;
private byte [] quantity;
public Product (String productName, String price, String quantity, String fileName) throws IOException {
//add id
int maxId = 0;
BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(fileName)));
String tempString;
while (true) {
if ((tempString = reader.readLine()) == null) {
reader.close();
break;
}
tempString = tempString.substring(0, 8);
if (tempString.indexOf(' ') != -1)
tempString = tempString.substring(0, tempString.indexOf(' '));
int tempId = Integer.parseInt(tempString);
if (tempId > maxId) {
maxId = tempId;
}
}
this.id = new byte[8];
for (int i = 0; i < 8; ++i) {
this.id [i] = ' ';
}
byte [] id = String.valueOf(maxId + 1).getBytes();
for (int i = 0; i < id.length; ++i) {
this.id[i] = id[i];
}
//add productName
while (productName.length() < 30) {
productName += ' ';
}
this.productName = productName.getBytes();
//add price
while (price.length() < 8)
price += ' ';
this.price = price.getBytes();
//add quantity
while (quantity.length() < 4)
quantity += ' ';
this.quantity = quantity.getBytes();
}
public void writeProduct(String fileName) throws IOException {
FileOutputStream outputStream = new FileOutputStream(fileName, true);
outputStream.write('\n');
outputStream.write(id);
outputStream.write(productName);
outputStream.write(price);
outputStream.write(quantity);
outputStream.close();
}
}