Подскажите, пожалуйста, что не так(
package com.javarush.task.task18.task1828;
import java.util.*;
import java.io.*;
/*
Прайсы 2
*/
public class Solution {
public static void main(String[] args) throws IOException{
if (args.length > 0){
String prodName = "";
/* String args0 = "-d";
String args1 = "198479";
String args2 = "gfbfgbgfbfg";
String args3 = "56.54";
String args4 = "12.3"; */
TreeMap<Integer, String> id_tree = new TreeMap<>();
BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
String reader = buf.readLine();
buf.close();
String id = "";
FileReader file = new FileReader(reader);
BufferedReader buf_read = new BufferedReader(file);
while(buf_read.ready()){
// while(!(reader = buf.readLine()).equals("end")){
try{
// id_tree.add(buf_read.readLine().substring(0,8).trim());
id_tree.put(Integer.parseInt(buf_read.readLine().substring(0,8).trim()), buf_read.readLine());
}catch(Exception e){}
}
file.close();
buf_read.close();
switch (args[0]){
case("-c"): try{
id = String.format("%-8d", args[1]);
}catch(IllegalFormatConversionException e){id = args[1];}
int max = 0;
try{
max = Integer.parseInt(id.trim());
}catch(NumberFormatException e){}
// String ops = id_tree.get(Integer.parseInt(id));
prodName = args[2];
float k_price = 0;
double k_quantity = 0;
try{
k_quantity = (args[4].length() < 4) ? Double.parseDouble(args[4].trim()) : Double.parseDouble(args[4].substring(0, 4).trim());
k_price = (args[3].length() < 8) ? Float.parseFloat(args[3].trim()) : Float.parseFloat(args[3].substring(0, 8).trim());
}catch(NumberFormatException e){}
String ups = String.format("%-8s%-30s%-8s%-4s", id, prodName, String.valueOf(k_price), String.valueOf(k_quantity));
for(Map.Entry<Integer, String> pair:id_tree.entrySet()){
if(pair.getKey().equals(max)){
id_tree.put(max, ups);
}
}
FileOutputStream writer = new FileOutputStream(reader, true);
for(Map.Entry<Integer, String> pair : id_tree.entrySet()){
writer.write(pair.getValue().getBytes());
}
// id_tree.forEach((s,s1)-> writer.write(s1.getBytes()));
writer.close();
break;
case("-d"): try{
id = String.format("%-8d", args[1]);
}catch(IllegalFormatConversionException e){id = args[1];}
id_tree.remove(Integer.parseInt(id.trim()));
FileOutputStream file_writer = new FileOutputStream(reader, true);
for (Map.Entry<Integer, String> pair : id_tree.entrySet()){
file_writer.write(pair.getValue().getBytes());
}
// id_tree.forEach((s, s1)-> file_writer.write(s1.getBytes()));
file_writer.close();
break;
}
}
}
}