File canWrite - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for File canWrite method.

This code example shows how to use the following methods:canWrite, equals, exists, renameTo, toString
        // Is this a rollover file? 
        String filename=file.getName();
        int i=filename.toLowerCase().indexOf(YYYY_MM_DD);
        if (i>=0)
        { 
            file=new File(dir,
                          filename.substring(0,i)+
                          _fileDateFormat.format(now)+
                          filename.substring(i+YYYY_MM_DD.length()));
        } 
             
        if (file.exists()&&!file.canWrite())
            throw new IOException("Cannot write log file "+file);
 
        // Do we need to change the output stream? 
        if (out==null || !file.equals(_file))
        { 
            // Yep 
            _file=file;
            if (!_append && file.exists())

9
CodeRank
This code example shows how to use the following methods:canWrite, isDirectory
    synchronized File getCacheDir() throws FileNotFoundException {
        File cacheDir = null;
        if (app != null)
            cacheDir = app.getCacheDir();
         
        if (cacheDir == null || !cacheDir.isDirectory() || !cacheDir.canWrite())
            throw new FileNotFoundException("Failed to find the cache directory. " + adviseToSetApp());
                     
        return cacheDir;
    } 
    @Override 
    public synchronized ClassDefiner getClassDefiner(ClassDefiner defaultDefiner, ClassLoader parentClassLoader) {
        if (classDefiner == null)
            try { 
                classDefiner = new AndroidClassDefiner(getCacheDir(), parentClassLoader);
            } catch (IOException ex) {
                throw new RuntimeException("Failed to instantiate the Android class definer : " + ex, ex);
            } 
        return classDefiner;
    } 
8
CodeRank
This code example shows how to use the following methods:canRead, canWrite
        // not implemented 
    } 
 
    public static FileAttributes getFileAttributes(File f) throws IOException
    { 
        boolean r = f.canRead();
        boolean w = f.canWrite();
         
        FileAccessPermissions permissions = new FileAccessPermissions(r, w, r, w, r, w);
         
        return new FileAttributes(null, permissions, PRIORITY_LOW);
    } 
 
    private FileAccessPermissions permissions;
    private int priority;
} 
8
CodeRank
This code example shows how to use the following methods:canRead, canWrite, exists, isDirectory, mkdirs
    public static boolean ensureDirectoryExistsAndIsReadWritable(File dir) {
        if (dir == null) {
            return false; 
        } 
 
        if (dir.exists()) {
            if (!dir.isDirectory()) {
                Log.w(TAG, dir + " exists but is not a directory.");
                return false; 
            } 
        } else { 
            if (dir.mkdirs()) {
                Log.i(TAG, "Created directory " + dir);
            } else { 
                Log.w(TAG, "Failed to create directory " + dir);
                return false; 
            } 
        } 
 
        if (!dir.canRead()) {

8
CodeRank
This code example shows how to use the following methods:canWrite, mkdir
				fs = context.openFileOutput(normalized, Context.MODE_PRIVATE);
			writer = new BufferedWriter(new OutputStreamWriter(fs));
 
		} else if (storageMode.equals("sdcard")) {
			File root = Environment.getExternalStorageDirectory();
			File morgDir = new File(root, "mobileorg");
			morgDir.mkdir();
			if (morgDir.canWrite()) {
				File orgFileCard = new File(morgDir, fileName);
				FileWriter orgFWriter = new FileWriter(orgFileCard, append);
				writer = new BufferedWriter(orgFWriter);
			} 
		} 
 
		return writer;
	} 
 
	public File getFile() {
		String storageMode = getStorageMode();
		if (storageMode.equals("internal") || storageMode.equals("")) {
8
CodeRank
This code example shows how to use the following methods:canRead, canWrite, exists, getCanonicalFile, isDirectory
   * exists or the mkdir fails. 
   * @param dir 
   * @return true on success, false on failure 
   */ 
  public static boolean mkdirsWithExistsCheck(File dir) {
    if (dir.mkdir() || dir.exists()) {
      return true; 
    } 
    File canonDir = null;
    try { 
      canonDir = dir.getCanonicalFile();
    } catch (IOException e) {
      return false; 
    } 
    String parent = canonDir.getParent();
    return (parent != null) && 
           (mkdirsWithExistsCheck(new File(parent)) &&
                                      (canonDir.mkdir() || canonDir.exists()));
  } 
   

8
CodeRank
This code example shows how to use the following methods:canWrite, exists
        FileOutputStream fileoutputstream = null;
 
        try 
        { 
            // CraftBukkit start - Don't attempt writing to file if it's read only 
            if (this.associatedFile.exists() && !this.associatedFile.canWrite())
            { 
                return; 
            } 
 
            // CraftBukkit end 
            fileoutputstream = new FileOutputStream(this.associatedFile);
            this.properties.store(fileoutputstream, "Minecraft server properties");
        } 
        catch (Exception exception)
        { 
            this.logger.logWarningException("Failed to save " + this.associatedFile, exception);
            this.logMessageAndSave();
        } 
        finally 
8
CodeRank
This code example shows how to use the following methods:canRead, canWrite, getName, isHidden
		 
		return fileName.equalsIgnoreCase("README");
	} 
 
	private boolean legalFile(File f) {
        return !f.getName().startsWith(".") && !f.isHidden() && f.canRead() && f.canWrite();
    } 
 
    @Override 
    public void init(String appPath, ServiceConfig params) throws Exception {
        super.init(appPath, params);
    } 
 
} 
7
CodeRank
This code example shows how to use the following methods:canRead, canWrite, exists
	public static boolean canChangeProperties() { 
		if(!WrapperManager.isControlledByNativeWrapper()) { 
			Logger.normal(WrapperConfig.class, "Cannot alter properties: not running under wrapper"); 
			return false; 
		} 
		File f = new File("wrapper.conf");
		if(!f.exists()) {
			Logger.normal(WrapperConfig.class, "Cannot alter properties: wrapper.conf does not exist"); 
			return false; 
		} 
		if(!f.canRead()) {
			Logger.normal(WrapperConfig.class, "Cannot alter properties: wrapper.conf not readable"); 
			return false; 
		} 
		if(!f.canWrite()) {
			Logger.normal(WrapperConfig.class, "Cannot alter properties: wrapper.conf not writable"); 
			return false; 
		} 
		if(!FileUtil.getCanonicalFile(f).getParentFile().canWrite()) {
			Logger.normal(WrapperConfig.class, "Cannot alter properties: parent dir not writable"); 
8
CodeRank
This code example shows how to use the following methods:canWrite, equals, exists, getName, getParent
        throws IOException 
    { 
        // Check directory 
        File file = new File(_filename);
        _filename=file.getCanonicalPath();
        file=new File(_filename);
        File dir= new File(file.getParent());
        if (!dir.isDirectory() || !dir.canWrite())
            throw new IOException("Cannot write log directory "+dir);
             
        Date now=new Date();
         
        // Is this a rollover file? 
        String filename=file.getName();
        int i=filename.toLowerCase().indexOf(YYYY_MM_DD);
        if (i>=0)
        { 
            file=new File(dir,
                          filename.substring(0,i)+
                          _fileDateFormat.format(now)+

7
CodeRank

Related File canWrite Questions & Answers:

canWrite Method Overview
Tests whether the application can modify the file denoted by this abstract pathname.
See Code Examples for other Java 8 File Methods: