本文整理汇总了Java中java.io.File.setReadable方法的典型用法代码示例。如果您正苦于以下问题:Java File.setReadable方法的具体用法?Java File.setReadable怎么用?Java File.setReadable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.io.File
的用法示例。
在下文中一共展示了File.setReadable方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onPause
import java.io.File; //导入方法依赖的package包/类
@Override
public void onPause() {
// From https://forum.xda-developers.com/xposed/how-to-save-load-module-settings-t3640881
super.onPause();
// Set preferences permissions to be world readable
// Workaround for Android N and above since MODE_WORLD_READABLE will cause security exception and FC.
final File dataDir = new File(getActivity().getApplicationInfo().dataDir);
final File prefsDir = new File(dataDir, "shared_prefs");
final File prefsFile = new File(prefsDir, getPreferenceManager().getSharedPreferencesName() + ".xml");
if (prefsFile.exists()) {
dataDir.setReadable(true, false);
dataDir.setExecutable(true, false);
prefsDir.setReadable(true, false);
prefsDir.setExecutable(true, false);
prefsFile.setReadable(true, false);
prefsFile.setExecutable(true, false);
}
}
示例2: changeFilePermisson4Win
import java.io.File; //导入方法依赖的package包/类
/**
* Change the permission of the file to --Readable, Writable, Executable--
*
* @param fileName
*/
public static void changeFilePermisson4Win(String fileName) {
File file = new File(fileName);
if (!file.exists()) {
return;
}
if (!file.canRead()) {
file.setReadable(true);
}
if (!file.canWrite()) {
file.setWritable(true);
}
if (!file.canExecute()) {
file.setExecutable(true);
}
}
示例3: writePrivateKey
import java.io.File; //导入方法依赖的package包/类
/**
* writes private key
*
* @param key String
*/
protected String writePrivateKey(String key) {
String uuid = UUID.randomUUID().toString();
String fileName = config.getDataDir() + "/" + uuid;
try (BufferedWriter bw = Files.newBufferedWriter(Paths.get(fileName))) {
bw.write(key);
bw.close();
File f = new File(fileName);
f.setExecutable(false, false);
f.setReadable(false, false);
f.setWritable(false, false);
f.setReadable(true, true);
f.setWritable(true, true);
logger.debug("file: " + fileName);
} catch (IOException e) {
logger.error("could not write file: " + fileName + " msg:"
+ e.getMessage());
}
return fileName;
}
示例4: retrieveRelevantFiles
import java.io.File; //导入方法依赖的package包/类
private final List<File> retrieveRelevantFiles(String filePath) {
final File path = new File(filePath);
if (!path.exists()) {
errorString = "Provided search path does not exist: " + filePath;
return null;
}
if (!path.isDirectory()) {
errorString = "Provided path exists but is not a directory: " + filePath;
return null;
}
if (!path.canRead()) {
if (!path.setReadable(true)) {
errorString = "Provided path exists but is not readable: " + filePath;
return null;
}
}
return retrieveRelevantFiles(path, 0);
}
示例5: initBundled
import java.io.File; //导入方法依赖的package包/类
private void initBundled() throws IOException {
File tmpDir = new File(System.getProperty("java.io.tmpdir"), "solc");
tmpDir.setReadable(true);
tmpDir.setWritable(true);
tmpDir.setExecutable(true);
tmpDir.mkdirs();
String solcPath = "/native/" + getOS() + "/solc/";
InputStream is = getClass().getResourceAsStream(solcPath + "file.list");
Scanner scanner = new Scanner(is);
while (scanner.hasNext()) {
String s = scanner.next();
File targetFile = new File(tmpDir, s);
InputStream fis = getClass().getResourceAsStream(solcPath + s);
Files.copy(fis, targetFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
if (solc == null) {
// first file in the list denotes executable
solc = targetFile;
solc.setExecutable(true);
}
targetFile.deleteOnExit();
}
tmpDir.deleteOnExit();
}
示例6: throws_exception_when_provided_java_file_is_not_accessible
import java.io.File; //导入方法依赖的package包/类
@Test(expected = IllegalArgumentException.class)
public void throws_exception_when_provided_java_file_is_not_accessible() throws IOException {
compiler.init(
folder.getRoot().getAbsolutePath(),
new DefaultDependencyResolver(),
new DefaultInternalCompiler()
);
final File javaFile = folder.newFile();
javaFile.setReadable(false);
compiler.compile(javaFile.getAbsolutePath(), null);
}
示例7: retrieveRelevantFiles
import java.io.File; //导入方法依赖的package包/类
private final List<File> retrieveRelevantFiles(String filePath, String nonce) {
final File path = new File(filePath);
if (!path.exists()) {
errorString = "Provided search path does not exist: " + filePath;
return null;
}
if (!path.isDirectory()) {
errorString = "Provided path exists but is not a directory: " + filePath;
return null;
}
if (!path.canRead()) {
if (!path.setReadable(true)) {
errorString = "Provided path exists but is not readable: " + filePath;
return null;
}
}
if (!path.canWrite()) {
if (!path.setWritable(true)) {
errorString = "Provided path exists but is not writable: " + filePath;
return null;
}
}
return retrieveRelevantFiles(path, nonce);
}
示例8: createFile
import java.io.File; //导入方法依赖的package包/类
private static File createFile(String path) {
if (DBG) Log.d(TAG, "createFile: " + path);
File f = new File(path);
if (f.exists())
return f;
try {
f.createNewFile();
f.setReadable(true, false);
} catch (IOException e) {
Log.e(TAG, "could not create file:" + path, e);
}
return f;
}
示例9: testFileSystemSecretsLocker_notReadable
import java.io.File; //导入方法依赖的package包/类
@Test(expected = IllegalArgumentException.class)
public void testFileSystemSecretsLocker_notReadable() {
File tmpdir = new File(System.getProperty("java.io.tmpdir") + "/foo");
tmpdir.deleteOnExit();
tmpdir.mkdir();
tmpdir.setReadable(false);
secretsLocker = new FileSystemSecretsLocker(tmpdir.getAbsolutePath());
}
开发者ID:eonian-technologies,项目名称:secrets-locker,代码行数:11,代码来源:FileSystemSecretsLockerTest_constructor.java
示例10: changeFilePermission755
import java.io.File; //导入方法依赖的package包/类
public static boolean changeFilePermission755(final File file) {
try {
if (file == null || !file.exists()) {
return false;
}
file.setReadable(true, false);
file.setExecutable(true, false);
file.setWritable(true, true);
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
示例11: testReadError
import java.io.File; //导入方法依赖的package包/类
@Test
public void testReadError() {
final Optional<Resource> res = CachedResource.find(readonly2, rdf.createIRI("trellis:repository/ldpnr"));
assertTrue(res.isPresent());
final File quads = new File(readonly2, RESOURCE_QUADS);
assumeTrue(quads.setReadable(false));
assertEquals(0L, res.get().stream().count());
quads.setReadable(true);
}
示例12: fixFilePermissions
import java.io.File; //导入方法依赖的package包/类
public static void fixFilePermissions() {
File folder = new File(Util.getUserDataDirectory(Process.myUid()) + File.separator + "shared_prefs");
folder.setReadable(true, false);
File[] files = folder.listFiles();
if (files != null)
for (File file : files)
if (file.getName().startsWith("biz.bokhorst.xprivacy.provider.") && file.getName().endsWith(".xml")
&& !file.getName().contains(".usage."))
file.setReadable(true, false);
}
示例13: configFileIsNotReadable
import java.io.File; //导入方法依赖的package包/类
@Test
public void configFileIsNotReadable() throws IOException {
File file = temp.newFile("application.yml");
file.setReadable(false);
when(env.getProperty(anyString())).thenReturn(file.getAbsolutePath());
try {
listener.onApplicationEvent(event);
fail();
} catch (ConfigFileValidationException e) {
String error = e.getErrors().get(0).getDefaultMessage();
assertThat(error, containsString("Config file " + file.getAbsolutePath() + " cannot be read."));
}
}
示例14: throws_exception_when_provided_workspace_is_not_readable
import java.io.File; //导入方法依赖的package包/类
@Test(expected = IllegalArgumentException.class)
public void throws_exception_when_provided_workspace_is_not_readable() throws IOException {
final File root = folder.newFolder();
root.setReadable(false);
compiler.init(root.getAbsolutePath(), new DefaultDependencyResolver(), new DefaultInternalCompiler());
}
示例15: shareHeapDump
import java.io.File; //导入方法依赖的package包/类
private void shareHeapDump() {
File heapDumpFile = getVisibleLeak().heapDump.heapDumpFile;
heapDumpFile.setReadable(true, false);
Intent intent = new Intent("android.intent.action.SEND");
intent.setType("application/octet-stream");
intent.putExtra("android.intent.extra.STREAM", Uri.fromFile(heapDumpFile));
startActivity(Intent.createChooser(intent, getString(R.string.__leak_canary_share_with)));
}