File canWrite() method in Java with examples Last Updated : 13 Dec, 2021 Comments Improve Suggest changes Like Article Like Report The canWrite()function is a part of File class in Java . This function determines whether the program can write the file denoted by the abstract path name.The function returns true if the abstract file path exists and the application is allowed to write the file. Function signature: public boolean canWrite() Syntax: file.canWrite() Parameters: This method does not accept any parameter. Return Value: The function returns boolean value representing whether the application is allowed to write the file or not. Exception: This method throws Security Exception if the write access to the file is denied Below programs illustrates the use of canWrite() function: Example 1: The file "F:\\program.txt" is writable Java // Java program to demonstrate // canWrite() method of File Class import java.io.*; public class solution { public static void main(String args[]) { // Get the file File f = new File("F:\\program.txt"); // Check if the specified file // can be written or not if (f.canWrite()) System.out.println("Can be written"); else System.out.println("Cannot be written"); } } Output: Can be written Example 2: The file "F:\\program1.txt" is writable Java // Java program to demonstrate // canWrite() method of File Class import java.io.*; public class solution { public static void main(String args[]) { // Get the file File f = new File("F:\\program1.txt"); // Check if the specified file // can be written or not if (f.canWrite()) System.out.println("Can be written"); else System.out.println("Cannot be written"); } } Output: Cannot be written Note: The programs might not run in an online IDE. Please use an offline IDE and set the path of the file. Comment More infoAdvertise with us Next Article File canWrite() method in Java with examples A andrew1234 Follow Improve Article Tags : Java Java-Functions Java-IO package Java-File Class Practice Tags : Java Similar Reads File createNewFile() method in Java with Examples The createNewFile() function is a part of File class in Java . This function creates new empty file. The function returns true if the abstract file path does not exist and a new file is created. It returns false if the filename already exists. Function signature: public boolean createNewFile() Synta 2 min read Files copy() Method in Java with Examples The copy() method of java.nio.file.Files Class is used to copy bytes from a file to I/O streams or from I/O streams to a file. I/O Stream means an input source or output destination representing different types of sources e.g. disk files. Methods: Based on the type of arguments passed, the Files cla 5 min read CharArrayWriter write() method in Java with Examples The write() method of CharArrayWriter class in Java is of three types: The write(int) method of CharArrayWriter class in Java is used to write a character to the writer in form of an integer. This write() method writes one character at a time to the CharArrayWriter.Syntax: public void write(int c) O 3 min read CharArrayWriter writeTo() method in Java with Examples The writeTo(Writer) method of CharArrayWriter class in Java is used to write the contents of the CharArrayWriter to another character stream.Syntax: public void writeTo(Writer out) throws IOException Parameters: This method accepts one parameter out that represents the output stream that is the dest 1 min read CharArrayWriter append() method in Java with Examples The append() method of CharArrayWriter class in Java is of three types: The append(char) method of CharArrayWriter class in Java is used to append the specified character to the writer. This append() method appends one character at a time to the CharArrayWriter and returns this CharArrayWriter.Synta 3 min read Like