I tested on my files and it is working but not passing third and forth condition. Can someone see mistake ?
if (args.length > 0 && (args[0].equals("-u") || args[0].equals("-d"))) {

            BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

            String file = reader.readLine();

            reader.close();

            FileInputStream inputStream = new FileInputStream(file);

            BufferedReader fileReader = new BufferedReader(new InputStreamReader(inputStream));

            Map<String, String> map = new TreeMap<>();

            while (fileReader.ready()) {

                String line = fileReader.readLine();

                String tempID = line.substring(0, 8);
                String rest = line.substring(8);

                map.put(tempID, rest);

            }

            fileReader.close();
            inputStream.close();

            int mapSize = map.size();

        String id = args[1];

        if (id.length() < 8) {

            for (int i = id.length(); i < 8; i++) {

                id += " ";

            }
        }

        String empty = "";

        FileOutputStream outputStreamDelete = new FileOutputStream(file);
        outputStreamDelete.write(empty.getBytes());
        outputStreamDelete.close();

        FileOutputStream outputStream = new FileOutputStream(file, true);

            switch (args[0]) {

                case "-u":

                    int countU = 0;

                    String productName = args[2];

                    if (productName.length() < 30) {

                        for (int i = productName.length(); i < 30; i++) {

                            productName += " ";

                        }
                    }

                    String price = args[3];

                    if (price.length() < 8) {

                        for (int i = price.length(); i < 8; i++) {

                            price += " ";

                        }
                    }

                    String quantity = args[4];

                    if (quantity.length() < 4) {

                        for (int i = quantity.length(); i < 4; i++) {

                            quantity += " ";

                        }
                    }

                    String updatedValue = productName + price + quantity;

                for (Map.Entry<String, String> data : map.entrySet()) {

                    String key = data.getKey();
                    String oldDAta = data.getValue();

                    if (key.equals(id)) {

                        countU++;
                        String update = key + updatedValue;

                        outputStream.write(update.getBytes());

                        if (countU < mapSize) {
                            outputStream.write(System.lineSeparator().getBytes());
                        }

                    }else {
                        countU++;

                        String old = key + oldDAta;

                        outputStream.write(old.getBytes());

                        if (countU < mapSize) {
                            outputStream.write(System.lineSeparator().getBytes());
                        }

                    }
                }

                outputStream.close();

                break;

                case "-d" :

                    map.remove(id);

                    int countD = 0;

                    for (Map.Entry<String, String> data : map.entrySet()) {

                        String key = data.getKey();
                        String oldDAta = data.getValue();

                        countD++;

                            String allArguments = key + oldDAta;

                            outputStream.write(allArguments.getBytes());
                        if (countD < mapSize) {
                            outputStream.write(System.lineSeparator().getBytes());
                        }
                    }

                    outputStream.close();

                    break;
            }
        }
    }