I have figured out how to create a hidden file in Java, now I need to write large amounts of data to the file. I keep getting the following exception:SEVERE: java.io.FileNotFoundException: <filepath>\tmp (Access is denied)
Here are two approaches I took to get try and get a solution, but I get the same exception for both approaches. Note: toOverwrite is the hidden file in both cases.
File fileByteText = new File("./testFile.txt");
File toOverwrite = new File("./tmp");
//Assume toOverwrite is hidden
boolean toReturn = true;
try {
byte[] fileByteText = FileUtils.readFileToByteArray(toGetTextFrom);
FileUtils.writeByteArrayToFile(toOverwrite, fileByteText, false);
toReturn = false;
} catch (IOException e) {
bam.severe(e);
toReturn = true;
}
Approach two using the same file objects:
try {
String fileText = FileUtils.readFileToString(toGetTextFrom);
FileWriter fw = new FileWriter(toOverwrite.getAbsoluteFile());
BufferedWriter bw = new BufferedWriter(fw);
bw.write(fileText);
bw.close();
toReturn = false;
} catch (IOException e1) {
bam.severe(e1);
toReturn = true;
}