本文整理了Java中java.io.File.setReadable()
方法的一些代码示例,展示了File.setReadable()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。File.setReadable()
方法的具体详情如下:
包路径:java.io.File
类名称:File
方法名:setReadable
[英]Equivalent to setReadable(readable, true).
[中]等同于setReadable(可读,true)。
代码示例来源:origin: robovm/robovm
/**
* Equivalent to setReadable(readable, true).
* @see #setReadable(boolean, boolean)
* @since 1.6
*/
public boolean setReadable(boolean readable) {
return setReadable(readable, true);
}
代码示例来源:origin: Tencent/tinker
/**
* create directory
*
* @param directoryPath
*/
public static void createDirectory(final String directoryPath) {
File file = new File(directoryPath);
if (!file.exists()) {
file.setReadable(true, false);
file.setWritable(true, true);
file.mkdirs();
}
}
代码示例来源:origin: apache/flink
private static void writeYarnProperties(Properties properties, File propertiesFile) {
try (final OutputStream out = new FileOutputStream(propertiesFile)) {
properties.store(out, "Generated YARN properties file");
} catch (IOException e) {
throw new RuntimeException("Error writing the properties file", e);
}
propertiesFile.setReadable(true, false); // readable for all.
}
代码示例来源:origin: koral--/android-gif-drawable
@SuppressWarnings("ResultOfMethodCallIgnored") //intended, nothing useful can be done
@SuppressLint("SetWorldReadable") //intended, default permission
private static void setFilePermissions(File outputFile) {
// Try change permission to rwxr-xr-x
outputFile.setReadable(true, false);
outputFile.setExecutable(true, false);
outputFile.setWritable(true);
}
代码示例来源:origin: square/spoon
@Override protected void plusRWX(File file) {
file.setReadable(true, false);
file.setWritable(true, false);
file.setExecutable(true, false);
}
}
代码示例来源:origin: apache/geode
public static Path createSecuredTempDirectory(String prefix) throws IOException {
Path tempDir = Files.createTempDirectory(prefix);
tempDir.toFile().setExecutable(true, true);
tempDir.toFile().setWritable(true, true);
tempDir.toFile().setReadable(true, true);
return tempDir;
}
}
代码示例来源:origin: Tencent/tinker
/**
* create file,full filename,signle empty file.
*
* @param fullFilename
* @return boolean
*/
public static boolean createFile(final String fullFilename) {
boolean result = false;
File file = new File(fullFilename);
createDirectory(file.getParent());
try {
file.setReadable(true, false);
file.setWritable(true, true);
result = file.createNewFile();
} catch (Exception e) {
throw new FileUtilException(e);
}
return result;
}
代码示例来源:origin: neo4j/neo4j
private void writePem( String type, byte[] encodedContent, File path ) throws IOException
{
path.getParentFile().mkdirs();
try ( PemWriter writer = new PemWriter( new FileWriter( path ) ) )
{
writer.writeObject( new PemObject( type, encodedContent ) );
writer.flush();
}
path.setReadable( false, false );
path.setWritable( false, false );
path.setReadable( true );
path.setWritable( true );
}
}
代码示例来源:origin: markzhai/AndroidPerformanceMonitor
private void shareHeapDump(BlockInfoEx blockInfo) {
File heapDumpFile = blockInfo.logFile;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
heapDumpFile.setReadable(true, false);
}
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("application/octet-stream");
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(heapDumpFile));
startActivity(Intent.createChooser(intent, getString(R.string.block_canary_share_with)));
}
代码示例来源:origin: square/leakcanary
@Override public void run() {
//noinspection ResultOfMethodCallIgnored
heapDumpFile.setReadable(true, false);
final Uri heapDumpUri = getUriForFile(getBaseContext(),
"com.squareup.leakcanary.fileprovider." + getApplication().getPackageName(),
heapDumpFile);
runOnUiThread(new Runnable() {
@Override public void run() {
startShareIntentChooser(heapDumpUri);
}
});
}
});
代码示例来源:origin: testcontainers/testcontainers-java
@BeforeClass
public static void setupContent() throws FileNotFoundException {
contentFolder.mkdir();
contentFolder.setReadable(true, false);
contentFolder.setWritable(true, false);
contentFolder.setExecutable(true, false);
File indexFile = new File(contentFolder, "index.html");
indexFile.setReadable(true, false);
indexFile.setWritable(true, false);
indexFile.setExecutable(true, false);
@Cleanup PrintStream printStream = new PrintStream(new FileOutputStream(indexFile));
printStream.println("This worked");
}
代码示例来源:origin: apache/nifi
@Before
public void prepDestDirectory() throws IOException {
final File targetDir = new File("target/move-target");
if (!targetDir.exists()) {
Files.createDirectories(targetDir.toPath());
return;
}
targetDir.setReadable(true);
for (final File file : targetDir.listFiles()) {
Files.delete(file.toPath());
}
}
代码示例来源:origin: testcontainers/testcontainers-java
@SuppressWarnings({"Duplicates", "ResultOfMethodCallIgnored"})
@BeforeClass
public static void setupContent() throws FileNotFoundException {
contentFolder.mkdir();
contentFolder.setReadable(true, false);
contentFolder.setWritable(true, false);
contentFolder.setExecutable(true, false);
File indexFile = new File(contentFolder, "index.html");
indexFile.setReadable(true, false);
indexFile.setWritable(true, false);
indexFile.setExecutable(true, false);
@Cleanup PrintStream printStream = new PrintStream(new FileOutputStream(indexFile));
printStream.println("This worked");
}
代码示例来源:origin: hamcrest/JavaHamcrest
public void testAReadableFile() { // Not all OSes will allow setting readability so have to be forgiving here.
file.setReadable(true);
assertMatches("matches readable file", FileMatchers.aReadableFile(), file);
if (file.setReadable(false)) {
assertDoesNotMatch("doesn't match unreadable file", FileMatchers.aReadableFile(), file);
}
}
代码示例来源:origin: apache/zookeeper
@Test
public void testUnreadableFileInput() throws Exception {
//skip this test on Windows, coverage on Linux
assumeTrue(!org.apache.zookeeper.Shell.WINDOWS);
File file = File.createTempFile("test", ".junit", testData);
file.setReadable(false, false);
file.deleteOnExit();
String absolutePath = file.getAbsolutePath();
String error = ZKUtil.validateFileInput(absolutePath);
assertNotNull(error);
String expectedMessage = "Read permission is denied on the file '" + absolutePath + "'";
assertEquals(expectedMessage, error);
}
代码示例来源:origin: neo4j/neo4j
@Test
void lockFileAndFailToDeleteDirectory()
{
File nOnDeletableDirectory= directory.directory( "c" );
CONTEXT.setValue( LOCKED_TEST_FILE_KEY, nonDeletableDirectory );
assertTrue( nonDeletableDirectory.setReadable( false, false ) );
}
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldLogIfConfigFileCouldNotBeRead() throws IOException
{
Log log = mock( Log.class );
File cOnfFile= testDirectory.file( "test.conf" );
assertTrue( confFile.createNewFile() );
assumeTrue( confFile.setReadable( false ) );
Config cOnfig= Config.fromFile( confFile ).withNoThrowOnFileLoadFailure().build();
config.setLogger( log );
verify( log ).error( "Unable to load config file [%s]: %s", confFile, confFile + " (Permission denied)" );
}
代码示例来源:origin: neo4j/neo4j
@Test( expected = ConfigLoadIOException.class )
public void mustThrowIfConfigFileCoutNotBeRead() throws IOException
{
File cOnfFile= testDirectory.file( "test.conf" );
assertTrue( confFile.createNewFile() );
assumeTrue( confFile.setReadable( false ) );
Config.fromFile( confFile ).build();
}
代码示例来源:origin: spotbugs/spotbugs
@Test
public void ignoreUnreadableFile() throws Exception {
File file = createZipFile();
file.deleteOnExit();
file.setReadable(false);
assumeFalse("File cannot be marked as unreadable, skipping test.", file.canRead());
FilesystemCodeBaseLocator locator = buildLocator(file);
assertHasNoCodeBase(ClassFactory.createFilesystemCodeBase(locator));
}
代码示例来源:origin: neo4j/neo4j
@Test
@EnabledOnOs( OS.LINUX )
void exceptionOnDirectoryDeletionIncludeTestDisplayName() throws IOException
{
CONTEXT.clear();
FailedTestExecutionListener failedTestListener = new FailedTestExecutionListener();
execute( "lockFileAndFailToDeleteDirectory", failedTestListener );
File lockedFile = CONTEXT.getValue( LOCKED_TEST_FILE_KEY );
assertNotNull( lockedFile );
assertTrue( lockedFile.setReadable( true, true ) );
FileUtils.deleteRecursively( lockedFile );
failedTestListener.assertTestObserver();
}