-3

I want to know how do I create a jar that will write to a .txt or generate a huge file once executed. It will either generate a huge file or keep writing to a file as fast as possible to bloat up the storage. The main point is to keep generating content or to take up the whole space of a storage. I am using this for my own purposes only.

Is this possible?

Thanks.

pleasega
  • 543
  • 1
  • 3
  • 21

1 Answers1

1

You can try something like this:

try(PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("myfile.txt", true)))) {

     while(true) {
           out.println("more text");
     }
}catch (IOException e) {
     //exception handling left as an exercise for the reader
}

Warning: This will potentially write a huge file ;) - You can increase the amount by writing more bytes at a time. Simple insert a lager text.

Marcinek
  • 2,144
  • 1
  • 19
  • 25