O
O
Oleg2021-06-22 20:13:05
Java
Oleg, 2021-06-22 20:13:05

How to erase lines from a file using a mask?

Perhaps I did not correctly ask the question .... But.
There is a file clogged with such "blocks"

class Fishing_splash_Soundshader : baseCharacter_SoundShader {
    samples[] = {{"DZ\sounds\Characters\actions\misc\fishing_splash_0", 1}, {"DZ\sounds\Characters\actions\misc\fishing_splash_1", 1}, {"DZ\sounds\Characters\actions\misc\fishing_splash_2", 1}};
    volume = 0.562341;
  };
  
  class Fishing_splash_small_Soundshader : baseCharacter_SoundShader {
    samples[] = {{"DZ\sounds\Characters\actions\misc\fishing_splash_small_0", 1}};
    volume = 0.562341;
  };
  
  class Fish_struggling_Soundshader : baseCharacter_SoundShader {
    samples[] = {{"DZ\sounds\Characters\actions\misc\fish_struggling_0", 1}, {"DZ\sounds\Characters\actions\misc\fish_struggling_1", 1}};
    volume = 0.562341;
  };


I have a line number pointing for example to "samples[] = {{"DZ\sounds\Characters\actions\misc\fishing_splash_small_0", 1}};" - the middle line of the second block of the class.

I threw a small code to remove a specific line (num) from a file
BufferedReader reader = new BufferedReader(new FileReader(sourceFile));
        BufferedWriter writer = new BufferedWriter(new FileWriter(outputFile));
        String line;
        int lineNumber = 0;
        while ((line = reader.readLine()) != null) {
            lineNumber++;
            if (lineNumber != num) {
                writer.write(line);
                writer.newLine();
            }
        }
        reader.close();
        writer.close();


And so I thought. And how to "explain" the program so that it deletes the entire block
class Fishing_splash_small_Soundshader : baseCharacter_SoundShader {
    samples[] = {{"DZ\sounds\Characters\actions\misc\fishing_splash_small_0", 1}};
    volume = 0.562341;
  };

if the line number falls into any part of it ....

Maybe there is something in the java stream for such tasks?
How to solve such a question?

Thanks for any insight.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question