Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

Tip of the Day
Language: Java
Expertise: Intermediate
Jul 25, 2017



Application Security Testing: An Integral Part of DevOps

Making a File Read-only Using Java

Files have multiple properties and they are interesting to use. In fact, your own file system can be developed using them. Create a file named PATH.txt and try this program twice to see how the setReadOnly() method works. Explore and enjoy!

import java.io.File;

public class ReadOnlyFile {
   public static void main(String[] args) 
      //File to choose
     String fileNameWithPath = "C:/PATH.txt";
     File file = new File(fileNameWithPath);
      System.out.println("File is writeable: " + file.canWrite());
     //If the file is writable, then making it read-only
     if (file.canWrite())
        System.out.println("File is writable. Making it read-only now");
M S Sridhar
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date