0

I have a Java test which uses File as follows to access a file:

File localFile = new File("/path/to/my/file/file.txt");

Because Im referencing a file in a particular location I must have that file in my project or the test will fail. Is there any I can generate a File of a specific size as part of my test?

This thread uses RandomAccessFile but I don't think that's what I'm looking for.

runnerpaul
  • 5,942
  • 8
  • 49
  • 118

1 Answers1

3

Try this code.

        File file = new File("/home/ok.txt");
        RandomAccessFile rafile;
        try {
            rafile = new RandomAccessFile(file, "rw");
            rafile.setLength(1024);

        } catch (Exception e) {
            e.printStackTrace();
        }
Onkar Musale
  • 909
  • 10
  • 25