In a previous task where we had to work with the CRUD, the arguments list had the only field capable of containing spaces enclosed by quotes, which the engine interpreted all as a single argument rather than breaking apart into multiple arguments. Like if we pretend I'm creating the first line in the example, would the arguments line be: -c Swim trunks, blue 159.00 12 or -c "Swim trunks, blue" 159.00 12 I'm assuming it's the second one because that's how it was done the other time (and it would just be a poorly designed system to use the first one). Also, when the conditions say: "Before adding a new line, re-write all of its contents to the file." Does "its contents" mean "the file's contents" or "the new line's contents"? I assumed it meant I am to rewrite the whole file again, copying all of the lines I've read from it previously and adding the new one at the end, which is why my writeToFile method only needs to know which file to write to. Anyway, my code's not doing too well on this one. Have a look if you like. The last condition about the file streams not being closed probably means something else went wrong. I probably took an unusual approach creating a separate class to handle a line of data from the file, but it seemed to make sense for easily manipulating it. EDIT: Here is my current code. No longer uses extra classes or methods, all done in main method. Still has same validation errors, though:
package com.codegym.task.task18.task1827;

/*
Prices

*/

import java.io.*;
import java.util.ArrayList;
import java.util.Scanner;

public class Solution
{

    public static void main(String[] args) throws Exception
    {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String filename = reader.readLine();
        reader.close();

        if(args.length > 0)
        {
            ArrayList<String> lines = new ArrayList<>();
            int maxID = 0;
            String line;
            Scanner scanner = new Scanner(filename);
            while(scanner.hasNextLine())
            {
                line = scanner.nextLine();
                maxID = Math.max(maxID, Integer.parseInt(line.substring(0,8)));
                lines.add(line);
            }
            scanner.close();
            String formattedLine = null;
            switch(args[0])
            {
                case "-c":
                    maxID++;
                    formattedLine = String.format("%-8s%-30s%-8s%-4s",("" + maxID), args[1], args[2], args[3]);
                    lines.add(formattedLine);
                    FileWriter output_c = new FileWriter(filename);
                    for(String s : lines)
                    {
                        output_c.write(s+"\n");
                    }
                    output_c.close();
                    break;
                case "-r":
                    for(String s : lines)
                    {
                        if(args[1].equals(s.substring(0,8)))
                        {
                            System.out.println(s);
                        }
                    }
                    break;
                case "-u":
                    FileWriter output_u = new FileWriter(filename);
                    formattedLine = String.format("%-8s%-30s%-8s%-4s",args[1],args[2],args[3],args[4]);
                    for(String s : lines)
                    {
                        if(args[1].equals(s.substring(0,8)))
                        {
                            lines.set(lines.indexOf(s),formattedLine);
                        }
                    }
                    for(String s : lines)
                    {
                        output_u.write(s+"\n");
                    }
                    output_u.close();
                    break;
                case "-d":
                    FileWriter output_d = new FileWriter(filename);
                    output_d.write("");
                    output_d.close();
                    output_d = new FileWriter(filename);
                    for(String s : lines)
                    {
                        if(args[1].equals(s.substring(0,8)))
                        {
                            lines.remove(s);
                        }
                    }
                    for(String s : lines)
                    {
                        output_d.write(s+"\n");
                    }
                    output_d.close();
                    break;
            }
        }
    }
}