当前位置: 首页>>代码示例>>Java>>正文


Java File.canWrite方法代码示例

本文整理汇总了Java中java.io.File.canWrite方法的典型用法代码示例。如果您正苦于以下问题:Java File.canWrite方法的具体用法?Java File.canWrite怎么用?Java File.canWrite使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.io.File的用法示例。


在下文中一共展示了File.canWrite方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: restore_ReadLater

import java.io.File; //导入方法依赖的package包/类
private void restore_ReadLater () {
    try {
        File sd = Environment.getExternalStorageDirectory();
        File data = Environment.getDataDirectory();

        if (sd.canWrite()) {
            String currentDBPath = "//data//" + "jae.KidsPortal.Browser"
                    + "//databases//" + "readLater_DB_v01.db";
            String backupDBPath = "//Android//" + "//data//" + "//browser.backup//" + "readLater_DB_v01.db";
            File currentDB = new File(data, currentDBPath);
            File backupDB = new File(sd, backupDBPath);

            FileChannel src = new FileInputStream(backupDB).getChannel();
            FileChannel dst = new FileOutputStream(currentDB).getChannel();
            dst.transferFrom(src, 0, src.size());
            src.close();
            dst.close();

            Snackbar.make(frameLayout, getString(R.string.toast_restore), Snackbar.LENGTH_LONG).show();
        }
    } catch (Exception e) {
        Snackbar.make(frameLayout, getString(R.string.toast_restore_not), Snackbar.LENGTH_LONG).show();
    }
}
 
开发者ID:JaeNuguid,项目名称:Kids-Portal-Android,代码行数:25,代码来源:Activity_settings_data.java

示例2: main

import java.io.File; //导入方法依赖的package包/类
public static void main(String[] args) throws FileNotFoundException {
    File ogrencilerDosya = new File(".\\config\\Ogrenciler.txt"); 
    // Mac: "./config/Ogrenciler.txt"
    
    if(!ogrencilerDosya.exists() || !ogrencilerDosya.canRead()
            || !ogrencilerDosya.isFile() ) {
        System.out.println("Dosya yok ya da okuma hakkı yok." 
                + ogrencilerDosya.getAbsolutePath() );
        return;
    }
    
    Scanner dosyaOkuyucu = new Scanner(ogrencilerDosya);

    File ciktiDosyasi = new File(".\\config\\Ogrenciler_cikti.txt"); 
    // Mac: "./config/Ogrenciler_cikti.txt"
    
    if (!ciktiDosyasi.canWrite()) {
        System.out.println("Yazma hakki yok");
        return;
    }
    
    PrintWriter dosyaYazici = new PrintWriter(ciktiDosyasi);

    // Dosyaya ek yapmak icin:
    // FileOutputStream fos = new FileOutputStream(ciktiDosyasi);
    // PrintWriter dosyaYazici2 = new PrintWriter(fos, true);
    for (int i = 0; dosyaOkuyucu.hasNextLine(); i++) {
        String mevcutSatir = dosyaOkuyucu.nextLine();
        System.out.println(mevcutSatir);
        dosyaYazici.println("Satir " + (i + 1) + ": " + mevcutSatir);
    }

    dosyaYazici.close();
    dosyaOkuyucu.close();
}
 
开发者ID:ozkansari,项目名称:MyCourses,代码行数:36,代码来源:DosyaOkumaOrnegiSade.java

示例3: openOutputStream

import java.io.File; //导入方法依赖的package包/类
public static FileOutputStream openOutputStream(File file) throws IOException
{
	if (file.exists())
	{
		if (file.isDirectory())
		{
			throw new IOException("File '" + file + "' exists but is a directory");
		}
		if (file.canWrite() == false)
		{
			throw new IOException("File '" + file + "' cannot be written to");
		}
	}
	else
	{
		File parent = file.getParentFile();
		if (parent != null && parent.exists() == false)
		{
			if (parent.mkdirs() == false)
			{
				throw new IOException("File '" + file + "' could not be created");
			}
		}
	}
	return new FileOutputStream(file);
}
 
开发者ID:nwpu043814,项目名称:AspriseOCR,代码行数:27,代码来源:Util.java

示例4: deleteFile

import java.io.File; //导入方法依赖的package包/类
public static boolean deleteFile(File file) {
    if (file.exists() && file.isFile() && file.canWrite()) {
        return file.delete();
    } else if (file.isDirectory()) {
        if (null != file && file.list() != null && file.list().length == 0) {
            return file.delete();
        } else {
            String[] fileList = file.list();
            for (String filePaths : fileList) {
                File tempFile = new File(file.getAbsolutePath() + "/" + filePaths);
                if (tempFile.isFile()) {
                    tempFile.delete();
                } else {
                    deleteFile(tempFile);
                    tempFile.delete();
                }
            }

        }
        if (file.exists()) {
            return file.delete();
        }
    }
    return false;
}
 
开发者ID:medalionk,项目名称:simple-share-android,代码行数:26,代码来源:FileUtils.java

示例5: getLogs

import java.io.File; //导入方法依赖的package包/类
/**
 * Find all log files within a directory
 *
 * @param logDir directory to search
 * @return List of data files within logDir
 */
static List<File> getLogs(File logDir) {
  List<File> result = Lists.newArrayList();
  File[] files = logDir.listFiles();
  if (files == null) {
    String msg = logDir + ".listFiles() returned null: ";
    msg += "File = " + logDir.isFile() + ", ";
    msg += "Exists = " + logDir.exists() + ", ";
    msg += "Writable = " + logDir.canWrite();
    throw new IllegalStateException(msg);
  }
  for (File file : files) {
    String name = file.getName();
    if (pattern.matcher(name).matches()) {
      result.add(file);
    }
  }
  return result;
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:25,代码来源:LogUtils.java

示例6: validate

import java.io.File; //导入方法依赖的package包/类
private void validate () throws Exception
{
    final String fileName = this.fileName.getText ();

    if ( fileName.length () == 0 )
    {
        throw new IllegalStateException ( Messages.FileNamePage_State_NotFileSelected );
    }

    final File file = new File ( fileName );

    if ( file.exists () && !file.isFile () )
    {
        throw new IllegalArgumentException ( String.format ( Messages.FileNamePage_State_FileNoFile, fileName ) );
    }
    if ( !file.canWrite () && file.exists () )
    {
        throw new IllegalArgumentException ( String.format ( Messages.FileNamePage_State_FileCantWrite, fileName ) );
    }
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:21,代码来源:FileNamePage.java

示例7: write

import java.io.File; //导入方法依赖的package包/类
@SneakyThrows
public void write(final File destination) {
  if (destination == null || !destination.canWrite() || !destination.exists() || !destination.isDirectory()) {
    throw new IllegalStateException("Cannot write to " + destination);
  }
  getCodeModel().build(destination);
}
 
开发者ID:camunda,项目名称:camunda-bpm-swagger,代码行数:8,代码来源:AbstractModel.java

示例8: isFileReadOnly

import java.io.File; //导入方法依赖的package包/类
static final boolean isFileReadOnly(final File file) {
  if (System.getProperty("os.name").startsWith("Windows")) {
    return !file.canWrite();
  }
  //All Unix-like OSes
  final Path path = Paths.get(file.getAbsolutePath());
  PosixFileAttributes attributes = null;
  try {
    attributes = Files.getFileAttributeView(path, PosixFileAttributeView.class).readAttributes();
  } catch (final IOException e) {
    // File presence is guaranteed. Ignore
    e.printStackTrace();
  }
  if (attributes == null) { return false; }

  // A file is read-only in Linux-derived OSes only when it has 0444 permissions.
  final Set<PosixFilePermission> permissions = attributes.permissions();
  int bits = 0;
  bits |= ((permissions.contains(PosixFilePermission.OWNER_READ))     ? 1 << 8 : 0);
  bits |= ((permissions.contains(PosixFilePermission.OWNER_WRITE))    ? 1 << 7 : 0);
  bits |= ((permissions.contains(PosixFilePermission.OWNER_EXECUTE))  ? 1 << 6 : 0);
  bits |= ((permissions.contains(PosixFilePermission.GROUP_READ))     ? 1 << 5 : 0);
  bits |= ((permissions.contains(PosixFilePermission.GROUP_WRITE))    ? 1 << 4 : 0);
  bits |= ((permissions.contains(PosixFilePermission.GROUP_EXECUTE))  ? 1 << 3 : 0);
  bits |= ((permissions.contains(PosixFilePermission.OTHERS_READ))    ? 1 << 2 : 0);
  bits |= ((permissions.contains(PosixFilePermission.OTHERS_WRITE))   ? 1 << 1 : 0);
  bits |= ((permissions.contains(PosixFilePermission.OTHERS_EXECUTE)) ? 1      : 0);
  //System.out.println(Util.zeroPad(Integer.toBinaryString(bits), 32));
  //System.out.println(Util.zeroPad(Integer.toOctalString(bits), 4));
  // Here we are going to ignore the Owner Write & Execute bits to allow root/owner testing.
  return ((bits & 0477) == 0444);
}
 
开发者ID:DataSketches,项目名称:memory,代码行数:33,代码来源:AllocateDirectMap.java

示例9: SerialPort

import java.io.File; //导入方法依赖的package包/类
public SerialPort(File device, int baudrate, int flags) throws SecurityException, IOException {
	/* Check access permission */
	if (!device.canRead() || !device.canWrite()) {
		try {
               /* Missing read/write permission, trying to chmod the file */
			Process su;
			su = Runtime.getRuntime().exec("/system/bin/su");
			String cmd = "chmod 666 " + device.getAbsolutePath() + "\n" + "exit\n";
			su.getOutputStream().write(cmd.getBytes());
			if ((su.waitFor() != 0) || !device.canRead() || !device.canWrite()) {
				throw new SecurityException();
			}
			Log.d(TAG,"target device missing read/write permission, trying to chmod the file");
		} catch (Exception e) {
			e.printStackTrace();
			throw new SecurityException();
		}
	}
	mFd = open(device.getAbsolutePath(), baudrate, flags);
	if (mFd == null) {
		Log.e(TAG, "native open returns null");
		throw new IOException();
	}
	path=device.getPath();
	mFileInputStream = new FileInputStream(mFd);
	mFileOutputStream = new FileOutputStream(mFd);
}
 
开发者ID:HelloHuDi,项目名称:usb-with-serial-port,代码行数:28,代码来源:SerialPort.java

示例10: canCreate

import java.io.File; //导入方法依赖的package包/类
private boolean canCreate(File file) {
	while (!file.exists()) {
		file = file.getParentFile();
		if (file == null) {
			return false;
		}
	}
	return file.canWrite();
}
 
开发者ID:gluonhq,项目名称:ide-plugins,代码行数:10,代码来源:ConfigureGluonProjectPage.java

示例11: compareFileAttributes

import java.io.File; //导入方法依赖的package包/类
public static void compareFileAttributes(File f1, MsgFileInfos f2) {
	if (!f1.getName().equals(f2.getName()))
		fail("name");
	if (f1.canRead() != f2.canRead() || f1.canWrite() != f2.canWrite() || f1.canExecute() != f2.canExecute())
		fail("attributes");
	if (f1.length() != f2.length())
		fail("length");
	if (f1.lastModified() != f2.lastModified())
		fail("time");
	if (f1.isFile() != f2.isFile() || f1.isDirectory() != f2.isDirectory())
		fail("status");
}
 
开发者ID:matthieu-labas,项目名称:JRF,代码行数:13,代码来源:UnitTesting.java

示例12: copyFile

import java.io.File; //导入方法依赖的package包/类
static void copyFile(File src, File dst) throws IOException {
    Path parent = dst.toPath().getParent();
    if (parent != null) {
        Files.createDirectories(parent);
    }
    Files.copy(src.toPath(), dst.toPath(), COPY_ATTRIBUTES, REPLACE_EXISTING);
    if (dst.isDirectory() && !dst.canWrite()) {
        dst.setWritable(true);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:11,代码来源:Utils.java

示例13: getTempFolder

import java.io.File; //导入方法依赖的package包/类
private static File getTempFolder() {
	final String tempFolder = StandardSystemProperty.JAVA_IO_TMPDIR.value();
	final File file = new File(tempFolder);
	if (!file.exists() || !file.canWrite()) {
		throw new RuntimeException("Cannot access temporary directory under: " + tempFolder);
	}
	return file;
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:9,代码来源:ShippedCodeAccess.java

示例14: deleteBlankPath

import java.io.File; //导入方法依赖的package包/类
/**
 * 删除空目录
 * <p/>
 * 返回 0代表成功 ,1 代表没有删除权限, 2代表不是空目录,3 代表未知错误
 *
 * @return
 */
public static int deleteBlankPath(String path) {
    File f = new File(path);
    if (!f.canWrite()) {
        return 1;
    }
    if (f.list() != null && f.list().length > 0) {
        return 2;
    }
    if (f.delete()) {
        return 0;
    }
    return 3;
}
 
开发者ID:z-chu,项目名称:FriendBook,代码行数:21,代码来源:FileUtil.java

示例15: deleteBlankPath

import java.io.File; //导入方法依赖的package包/类
public static int deleteBlankPath(String path) {
	File f = new File(path);
	if (!f.canWrite()) {
		return 1;
	}
	if (f.list() != null && f.list().length > 0) {
		return 2;
	}
	if (f.delete()) {
		return 0;
	}
	return 3;
}
 
开发者ID:coding-dream,项目名称:Notebook,代码行数:14,代码来源:FileUtils.java


注:本文中的java.io.File.canWrite方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。