I am working on an Android app and trying to create a file of a certain size that won't be sparse. I literally want it to take up space on the Android device.
Here's what I have so far, I'm fairly new to Java and tried a couple different things to fill (takes waaay to long if the file is big like 5 GB) or append to the end (doesn't work? maybe I did it wrong).
File file = new File(dir, "testFile.txt");
try {
RandomAccessFile f = new RandomAccessFile(file, "rw");
f.setLength((long) userInputNum * 1048576 * 1024);
f.close();
} catch (IOException e) {
e.printStackTrace();
}
Currently, what's happening is the file is created and say I want it to be 5 GB, in the file details it says it's 5 GB but it's not actually taking up space on the device (this is a sparse file as I have found out). How can I make it create the file not sparse or what's a quick way to fill the file? I can use a command on pc/mac to make the file and push it to the device but I want the app to do it.