I was wondering wether it is possible to create or simulate a file with a content set at creation and the assurance that nobody can ever change the file. If possible, can I
If you simply just need to create a Read-Only file, then won't the code below be sufficient? Unless I am missing something from your question:
import java.io.File;
import java.io.IOException;
public class FileAttributesDemo {
public static void main(String[] args) throws IOException {
// Create a new file, by default canWrite=true, readonly=false
File file = new File("test.txt");
if (file.exists()) {
file.delete();
}
file.createNewFile();
System.out.println("Before. canWrite?" + file.canWrite());
// set to read-only, atau canWrite = false */
file.setWritable(false);
System.out.println("After. canWrite?" + file.canWrite());
}
}