Example usage for java.io File canWrite

List of usage examples for java.io File canWrite

Introduction

In this page you can find the example usage for java.io File canWrite.

Prototype

public boolean canWrite() 

Source Link

Document

Tests whether the application can modify the file denoted by this abstract pathname.

Usage

From source file:Main.java

public static boolean checkCanWrite(File file) {
    if (file.canWrite())
        return true;
    return false;
}

From source file:Main.java

public static boolean isProtected(File path) {
    return (!path.canRead() && !path.canWrite());
}

From source file:Main.java

public static int deleteBlankPath(String path) {
    File f = new File(path);
    if (!f.canWrite()) {
        return 1;
    }//from   w ww .j a  v a 2  s . com
    if (f.list() != null && f.list().length > 0) {
        return 2;
    }
    if (f.delete()) {
        return 0;
    }
    return 3;
}

From source file:Main.java

public static boolean isDirectoryValid(String path) {
    File file = new File(path);
    if (!file.canWrite()) {
        return false;
    }// ww  w.j av  a2s  .co  m
    StatFs sf = new StatFs(file.getPath());
    long availCount = sf.getAvailableBlocks();
    if (availCount > 0) {
        return true;
    }
    return false;
}

From source file:com.microsoft.alm.common.utils.ArgumentHelper.java

public static void checkIfFileWriteable(final File file) {
    if (!file.canWrite()) {
        throw new IllegalArgumentException(String.format(NOT_WRITEABLE_FILE_MSG, file.getPath()));
    }/*from w w w . j  a  va  2s . co  m*/
}

From source file:Main.java

public static boolean canWriteOrCreate(File file) {
    if (file.exists()) {
        return file.canWrite();
    }//from w  ww .  j  a v a 2s  .  c  o m
    File parent = file.getParentFile();
    return parent != null && parent.exists() && parent.canWrite();
}

From source file:com.mirth.connect.util.AttachmentUtil.java

public static void writeToFile(String filePath, Attachment attachment, boolean binary) throws IOException {
    File file = new File(filePath);
    if (!file.canWrite()) {
        String dirName = file.getPath();
        int i = dirName.lastIndexOf(File.separator);
        if (i > -1) {
            dirName = dirName.substring(0, i);
            File dir = new File(dirName);
            dir.mkdirs();/*from w ww.  j  a va2s . com*/
        }
        file.createNewFile();
    }

    if (attachment != null && StringUtils.isNotEmpty(filePath)) {
        FileUtils.writeByteArrayToFile(file,
                binary ? Base64Util.decodeBase64(attachment.getContent()) : attachment.getContent());
    }
}

From source file:Main.java

public static boolean isFBCanRW() {
    try {//from w w w  .j  a  va 2  s  . co m
        File fbFile = new File("/dev/graphics/fb0");
        return fbFile.canRead() && fbFile.canWrite();
    } catch (Exception exception) {
        return false;
    }
}

From source file:Main.java

public static boolean isSDCardAvailable() {
    File sdcard = Environment.getExternalStorageDirectory();
    return sdcard.exists() && sdcard.canWrite();
}

From source file:Main.java

public static void valiFileCanWrite(File file) throws IOException {
    if (!file.canWrite()) {
        throw new IOException("For file '" + file.getName() + "' not write access!");
    }/*from  w  w w .j  ava  2  s  .co  m*/
}