Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.tutorialspoint;
- import java.io.File;
- public class FileDemo {
- public static void main(String[] args) {
- File f = null;
- boolean bool = false;
- try {
- // create new File object
- f = new File("C:/test.txt");
- // returns true if file exists
- bool = f.exists();
- // if file exists
- if(bool) {
- // set file access to writable for everybody
- bool = f.setWritable(true, false);
- // print
- System.out.println("setWritable() succeeded?: "+bool);
- // checks whether the file is writable
- bool = f.canWrite();
- // prints
- System.out.print("Is file writable?: "+bool);
- }
- } catch(Exception e) {
- // if any error occurs
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement