how to set read only access for file using java
问题 How to set read-only access for a file that's been created and written using java InputStream API. 回答1: In my opinion, it's good to check whether the file has been created or exists first and then set the read only flag. File file = new File("C:/path/file.txt"); if (file.exists()) { file.setReadOnly(); } else { System.out.println("File does not exists."); } 回答2: Well their are two ways to do it. The first would be: myFile.setReadable(false); . This make the file unreadable by all applications