Не проходит по 3 и 4 пунктам. Знатоки, объясните пожалуйста!!!
package com.javarush.task.task18.task1828;
/*
Прайсы 2
*/
import java.io.*;
import java.nio.file.Files;
import java.nio.file.Paths;
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String pathFile = reader.readLine();
reader.close();
if (args.length != 0) {
if (args[0].equals("-d")) { removeProduct(pathFile, args[1]); }
else if (args[0].equals("-u")) {
String newProduct = String.format("%-8s%-30.30s%-8.8s%-4.4s", args[1], args[2], args[3], args[4]);
updateInformationProduct(pathFile, args[1], newProduct);
}
}
}
private static void removeProduct(String pathFile, String id) {
try(BufferedReader bufferedReader = new BufferedReader(new
InputStreamReader(new FileInputStream(pathFile), "Cp1251"))) {
String readLine;
StringBuilder stringBuffer = new StringBuilder();
while ((readLine = bufferedReader.readLine()) != null) {
if (readLine.substring(0, 8).trim().equals(id)) continue;
stringBuffer.append(readLine).append(System.lineSeparator());
}
Files.write(Paths.get(pathFile), stringBuffer.toString().getBytes("Cp1251"));
} catch (IOException e) {
e.printStackTrace();
}
}
private static void updateInformationProduct(String pathFile, String id, String newProduct) {
try(BufferedReader bufferedReader = new BufferedReader(new
InputStreamReader(new FileInputStream(pathFile), "Cp1251"))) {
String readLine;
StringBuilder stringBuilder = new StringBuilder();
while ((readLine = bufferedReader.readLine()) != null) {
if (readLine.substring(0, 8).trim().equals(id)) {
stringBuilder.append(newProduct).append(System.lineSeparator());
} else stringBuilder.append(readLine).append(System.lineSeparator());
}
Files.write(Paths.get(pathFile), stringBuilder.toString().getBytes("Cp1251"));
} catch (IOException e) {
e.printStackTrace();
}
}
}