Tabnine Logo
File.canWrite
Code IndexAdd Tabnine to your IDE (free)

How to use
canWrite
method
in
java.io.File

Best Java code snippets using java.io.File.canWrite (Showing top 20 results out of 13,824)

Refine searchRefine arrow

  • File.exists
  • File.<init>
  • File.isDirectory
  • File.mkdirs
  • File.getAbsolutePath
origin: square/leakcanary

private boolean directoryWritableAfterMkdirs(File directory) {
 boolean success = directory.mkdirs();
 return (success || directory.exists()) && directory.canWrite();
}
origin: jeasonlzy/okhttp-OkGo

/**
 * If the folder can be written.
 *
 * @param path path.
 * @return True: success, or false: failure.
 */
public static boolean canWrite(String path) {
  return new File(path).canWrite();
}
origin: spring-projects/spring-framework

/**
 * This implementation checks whether the underlying file is marked as writable
 * (and corresponds to an actual file with content, not to a directory).
 * @see java.io.File#canWrite()
 * @see java.io.File#isDirectory()
 */
@Override
public boolean isWritable() {
  return (this.file != null ? this.file.canWrite() && !this.file.isDirectory() :
      Files.isWritable(this.filePath) && !Files.isDirectory(this.filePath));
}
origin: apache/storm

  private static void validateCreateOutputDir(File dir) {
    if (!dir.exists()) {
      dir.mkdirs();
    }
    if (!dir.canWrite()) {
      throw new IllegalStateException(dir.getName() + " does not have write permissions.");
    }
    if (!dir.isDirectory()) {
      throw new IllegalStateException(dir.getName() + " is not a directory.");
    }
  }
}
origin: bumptech/glide

 @Override
 public File getCacheDirectory() {
  File internalCacheDirectory = getInternalCacheDirectory();
  // Already used internal cache, so keep using that one,
  // thus avoiding using both external and internal with transient errors.
  if ((null != internalCacheDirectory) && internalCacheDirectory.exists()) {
   return internalCacheDirectory;
  }
  File cacheDirectory = context.getExternalCacheDir();
  // Shared storage is not available.
  if ((cacheDirectory == null) || (!cacheDirectory.canWrite())) {
   return internalCacheDirectory;
  }
  if (diskCacheName != null) {
   return new File(cacheDirectory, diskCacheName);
  }
  return cacheDirectory;
 }
}, diskCacheSize);
origin: yanzhenjie/NoHttp

public static boolean sdCardIsAvailable() {
  if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
    File sd = new File(Environment.getExternalStorageDirectory().getAbsolutePath());
    return sd.canWrite();
  } else return false;
}
origin: scouter-project/scouter

private static synchronized void openFile(String prefix) throws IOException {
  if (pw == null && StringUtil.isEmpty(conf.log_dir) == false) {
    File root = new File(conf.log_dir);
    if (root.canWrite() == false) {
      root.mkdirs();
    }
    if (root.canWrite() == false) {
      return;
    }
    if (conf.log_rotation_enabled) {
      File file = new File(conf.log_dir, "scouter-" + prefix + "-" + DateUtil.yyyymmdd() + ".log");
      FileWriter fw = new FileWriter(file, true);
      pw = new PrintWriter(fw);
      logfile = file;
    } else {
      File file = new File(conf.log_dir, "scouter-" + prefix + ".log");
      pw = new PrintWriter(new FileWriter(file, true));
      logfile = file;
    }
  }
}
origin: spotbugs/spotbugs

static SrcKind get(File f) {
  if (f.exists() && f.isDirectory() && f.canWrite()) {
    return DIR;
  }
  if (!f.exists()) {
    if (f.getName().endsWith(".zip")) {
      return ZIP;
    }
    if (f.getName().endsWith(".z0p.gz")) {
      return Z0P_GZ;
    }
  }
  throw new IllegalArgumentException("Invalid src destination: " + f);
}
origin: commons-io/commons-io

/**
 * Tests that we can write to the lock directory.
 *
 * @param lockDir  the File representing the lock directory
 * @throws IOException if we cannot write to the lock directory
 * @throws IOException if we cannot find the lock file
 */
private void testLockDir(final File lockDir) throws IOException {
  if (!lockDir.exists()) {
    throw new IOException(
        "Could not find lockDir: " + lockDir.getAbsolutePath());
  }
  if (!lockDir.canWrite()) {
    throw new IOException(
        "Could not write to lockDir: " + lockDir.getAbsolutePath());
  }
}
origin: androidannotations/androidannotations

public static File resolveOutputDirectory(ProcessingEnvironment processingEnv) throws FileNotFoundException {
  File rootProject = FileHelper.findRootProject(processingEnv);
  // Target folder - Maven
  File targetFolder = new File(rootProject, "target");
  if (targetFolder.isDirectory() && targetFolder.canWrite()) {
    return targetFolder;
  }
  // Build folder - Gradle
  File buildFolder = new File(rootProject, "build");
  if (buildFolder.isDirectory() && buildFolder.canWrite()) {
    return buildFolder;
  }
  // Bin folder - Eclipse
  File binFolder = new File(rootProject, "bin");
  if (binFolder.isDirectory() && binFolder.canWrite()) {
    return binFolder;
  }
  // Fallback to projet root folder
  return rootProject;
}
origin: org.codehaus.plexus/plexus-utils

private static void checkCanWrite( File destination )
  throws IOException
{
  // make sure we can write to destination
  if ( destination.exists() && !destination.canWrite() )
  {
    final String message = "Unable to open file " + destination + " for writing.";
    throw new IOException( message );
  }
}
origin: apache/storm

private static void validateCreateOutputDir(File dir) {
  if (!dir.exists()) {
    dir.mkdirs();
  }
  if (!dir.canWrite()) {
    throw new IllegalStateException(dir.getName() + " does not have write permissions.");
  }
  if (!dir.isDirectory()) {
    throw new IllegalStateException(dir.getName() + " is not a directory.");
  }
}
origin: oldmanpushcart/greys-anatomy

private History initHistory() throws IOException {
  final File WORK_DIR = new File(WORKING_DIR);
  final File historyFile = new File(WORKING_DIR + separatorChar + HISTORY_FILENAME);
  if (WORK_DIR.canWrite()
      && WORK_DIR.canRead()
      && ((!historyFile.exists() && historyFile.createNewFile()) || historyFile.exists())) {
    return new FileHistory(historyFile);
  }
  return new MemoryHistory();
}
origin: scouter-project/scouter

public static void main(String[] args) throws IOException {
  String path = getJarLocation(FileUtil.class);
  System.out.println(path);
  new File(path, "test.txt").createNewFile();
  System.out.println(new File(path).canWrite());
  System.out.println(new File(path).getAbsolutePath());
}
origin: scouter-project/scouter

private static synchronized void openFile(String prefix) throws IOException {
  if (pw == null && StringUtil.isEmpty(conf.log_dir) == false) {
    File root = new File(conf.log_dir);
    if (root.canWrite() == false) {
      root.mkdirs();
    }
    if (root.canWrite() == false) {
      return;
    }
    if (conf.log_rotation_enabled) {
      File file = new File(conf.log_dir, "scouter-" + prefix + "-" + DateUtil.yyyymmdd() + ".log");
      FileWriter fw = new FileWriter(file, true);
      pw = new PrintWriter(fw);
      logfile = file;
    } else {
      File file = new File(conf.log_dir, "scouter-" + prefix + ".log");
      pw = new PrintWriter(new FileWriter(file, true));
      logfile = file;
    }
  }
}
origin: debezium/debezium

/**
 * Set the parent directory where the server's logs and snapshots will be kept.
 * @param dataDir the parent directory for the server's logs and snapshots; may be null if a temporary directory will be used
 * @return this instance to allow method chaining; never null
 * @throws IllegalArgumentException if the supplied file is not a directory or not writable
 */
public ZookeeperServer setStateDirectory(File dataDir) {
  if ( dataDir != null && dataDir.exists() && !dataDir.isDirectory() && !dataDir.canWrite() && !dataDir.canRead() ) {
    throw new IllegalArgumentException("The directory must be readable and writable");
  }
  this.dataDir = dataDir;
  return this;
}
origin: org.apache.commons/commons-io

/**
 * Tests that we can write to the lock directory.
 *
 * @param lockDir  the File representing the lock directory
 * @throws IOException if we cannot write to the lock directory
 * @throws IOException if we cannot find the lock file
 */
private void testLockDir(File lockDir) throws IOException {
  if (!lockDir.exists()) {
    throw new IOException(
        "Could not find lockDir: " + lockDir.getAbsolutePath());
  }
  if (!lockDir.canWrite()) {
    throw new IOException(
        "Could not write to lockDir: " + lockDir.getAbsolutePath());
  }
}
origin: yanzhenjie/NoHttp

/**
 * If the folder can be written.
 *
 * @param path path.
 * @return True: success, or false: failure.
 */
public static boolean canWrite(String path) {
  return new File(path).canWrite();
}
origin: apache/ignite

/**
 * Initializes temporary directory path. Path consists of base path
 * (either {@link #tmpDirPath} value or {@code java.io.tmpdir}
 * system property value if first is {@code null}) and path relative
 * to base one - {@link #DEPLOY_TMP_ROOT_NAME}/{@code local node ID}.
 *
 * @throws org.apache.ignite.spi.IgniteSpiException Thrown if temporary directory could not be created.
 */
private void initializeTemporaryDirectoryPath() throws IgniteSpiException {
  String tmpDirPath = this.tmpDirPath == null ? System.getProperty("java.io.tmpdir") : this.tmpDirPath;
  if (tmpDirPath == null)
    throw new IgniteSpiException("Error initializing temporary deployment directory.");
  File dir = new File(tmpDirPath + File.separator + DEPLOY_TMP_ROOT_NAME + File.separator +
    ignite.configuration().getNodeId());
  if (!U.mkdirs(dir))
    throw new IgniteSpiException("Error initializing temporary deployment directory: " + dir);
  if (!dir.isDirectory())
    throw new IgniteSpiException("Temporary deployment directory path is not a valid directory: " + dir);
  if (!dir.canRead() || !dir.canWrite())
    throw new IgniteSpiException("Can not write to or read from temporary deployment directory: " + dir);
  this.tmpDirPath = tmpDirPath;
  deployTmpDirPath = dir.getPath();
}
origin: hs-web/hsweb-framework

  private static State valid(File file) {
    File parentPath = file.getParentFile();

    if ((!parentPath.exists()) && (!parentPath.mkdirs())) {
      return new BaseState(false, AppInfo.FAILED_CREATE_FILE);
    }

    if (!parentPath.canWrite()) {
      return new BaseState(false, AppInfo.PERMISSION_DENIED);
    }

    return new BaseState(true);
  }
}
java.ioFilecanWrite

Javadoc

Indicates whether the current context is allowed to write to this file.

Popular methods of File

  • <init>
    Creates a new File instance by converting the givenfile: URI into an abstract pathname. The exact fo
  • exists
    Tests whether the file or directory denoted by this abstract pathname exists.
  • getAbsolutePath
    Returns the absolute pathname string of this abstract pathname. If this abstract pathname is already
  • getName
    Returns the name of the file or directory denoted by this abstract pathname. This is just the last n
  • isDirectory
  • mkdirs
  • delete
    Deletes the file or directory denoted by this abstract pathname. If this pathname denotes a director
  • listFiles
    Returns an array of abstract pathnames denoting the files and directories in the directory denoted b
  • getParentFile
    Returns the abstract pathname of this abstract pathname's parent, or null if this pathname does not
  • getPath
    Converts this abstract pathname into a pathname string. The resulting string uses the #separator to
  • isFile
  • length
    Returns the length of the file denoted by this abstract pathname. The return value is unspecified if
  • isFile,
  • length,
  • toURI,
  • createTempFile,
  • createNewFile,
  • toPath,
  • mkdir,
  • lastModified,
  • toString,
  • getCanonicalPath

Popular in Java

  • Start an intent from android
  • scheduleAtFixedRate (Timer)
  • runOnUiThread (Activity)
  • getSharedPreferences (Context)
  • ResultSet (java.sql)
    An interface for an object which represents a database table entry, returned as the result of the qu
  • BoxLayout (javax.swing)
  • JButton (javax.swing)
  • JCheckBox (javax.swing)
  • XPath (javax.xml.xpath)
    XPath provides access to the XPath evaluation environment and expressions. Evaluation of XPath Expr
  • SAXParseException (org.xml.sax)
    Encapsulate an XML parse error or warning.> This module, both source code and documentation, is in t
  • CodeWhisperer alternatives
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now