How to check whether file is writable or file has write permission in java?

DeeKay August 27, 2011 at 6:32 pm · java.io

Below java code shows how to check whether file is writable or file has write permission –

<br />
/****************************************************************************************<br />
 * Created on 08-2011 Copyright(c) http://kodehelp.com All Rights Reserved.<br />
 ****************************************************************************************/<br />
package com.kodehelp.javaio;</p>
<p>import java.io.File;</p>
<p>/**<br />
 * Created by http://kodehelp.com<br />
 * Date: 8/27/11<br />
 */<br />
public class CanWriteFile {<br />
    public static void main(String args[]){<br />
        File file = new File("/demo.txt");<br />
        System.out.println(file.canWrite() ? "is writable" : "is not writable");<br />
    }<br />
}<br />