I need to get the size of a file, but I keep on getting 0 as the size, which is not the actual size.
private void dodAlgorithm() throws IOException {
int count;
int randomValue;
long fileSize;
File file = new File(filename);
BufferedWriter writer = new BufferedWriter(new FileWriter(file));
SecureRandom random = new SecureRandom();
if(file.exists()) {
fileSize = file.length();
}
else {
JOptionPane.showMessageDialog(null, "");
return;
}
// Overwrite the file with 0's.
for(count = 0; count < fileSize; count++) {
writer.write(0);
}
// Overwrite the file with 1's.
for(count = 0; count < fileSize; count++) {
writer.write(1);
}
// Overwrite the file with random numbers.
for(count = 0; count < fileSize; count++) {
randomValue = random.nextInt();
writer.write(randomValue);
txtHexValues.append(Integer.toHexString(randomValue) + " ");
}
// Close the file and delete it.
writer.close();
file.delete();
JOptionPane.showMessageDialog(null, "Done!");
}