I suppose I've completed all requirements, but it said I didn't re-write the contents. what's wrong? please save me!
package com.codegym.task.task18.task1827;
/*
Prices
*/
import java.io.*;
import java.util.ArrayList;
public class Solution {
public static void main(String[] args) throws Exception {
if (args.length == 0) {return;}
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String fileName = reader.readLine();
reader.close();
BufferedReader bReader = new BufferedReader(new FileReader(fileName));
FileWriter fileWriter = new FileWriter(fileName, true);
int maxId = 0;
String line;
String product, id, productName, price, quantity;
if (args[0].equals("-c")) {
while (bReader.ready()) {
line = bReader.readLine();
id = line.substring(0, 8).trim();
productName = line.substring(8, 38).trim();
price = line.substring(38, 46).trim();
quantity = line.substring(46, 50).trim();
product = id + productName + price + quantity;
fileWriter.write(product +"\n");
int num = Integer.parseInt(id);
if(num > maxId) {
maxId = num;
}
}
String idNew = String.valueOf(++maxId);
String newProduct = String.format("%-8s%-30s%-8s%-4s", idNew, args[1], args[2], args[3]);
fileWriter.write(newProduct);
}
bReader.close();
fileWriter.close();
}
}