Follow these steps to implement the example:
- First, implement a class that will simulate a text file. Create a class named FileMock with two attributes: a String array named content and int named index. They will store the content of the file and the line of the simulated file that will be retrieved:
public class FileMock { private String[] content; private int index;
- Implement the constructor of the class that initializes the content of the file with random characters:
public FileMock(int size, int length){ content = new String[size]; for (int i = 0; i< size; i++){ StringBuilder buffer = new StringBuilder(length); for (int j = 0; j < length; j++){ int randomCharacter= (int)Math.random()*255; buffer.append((char)randomCharacter); ...