congrats Icon
New! Tabnine Pro 14-day free trial
Start a free trial
Tabnine Logo
File.setWritable
Code IndexAdd Tabnine to your IDE (free)

How to use
setWritable
method
in
java.io.File

Best Java code snippets using java.io.File.setWritable (Showing top 20 results out of 2,664)

Refine searchRefine arrow

  • File.<init>
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: typ0520/fastdex

/**
 * 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: 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: ethereum/ethereumj

public static boolean recursiveDelete(String fileName) {
  File file = new File(fileName);
  if (file.exists()) {
    //check if the file is a directory
    if (file.isDirectory()) {
      if ((file.list()).length > 0) {
        for(String s:file.list()){
          //call deletion of file individually
          recursiveDelete(fileName + System.getProperty("file.separator") + s);
        }
      }
    }
    file.setWritable(true);
    boolean result = file.delete();
    return result;
  } else {
    return false;
  }
}
origin: typ0520/fastdex

/**
 * 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: redisson/redisson

File extractedLibFile = new File(targetFolder, extractedLibFileName);
      extractedLibFile.setWritable(true, true) &&
      extractedLibFile.setExecutable(true);
  if (!success) {
  return new File(targetFolder, extractedLibFileName);
origin: apache/ignite

File file = new File(System.getProperty("java.io.tmpdir"), "ignite.lastport.tmp");
file.setWritable(true, false);
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("<html><body>This worked</body></html>");
}
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("<html><body>This worked</body></html>");
}
origin: apache/flink

@Test
public void testDeleteQuietly() throws Exception {
  // should ignore the call
  FileUtils.deleteDirectoryQuietly(null);
  File doesNotExist = new File(tmp.getRoot(), "abc");
  FileUtils.deleteDirectoryQuietly(doesNotExist);
  File cannotDeleteParent = tmp.newFolder();
  File cannotDeleteChild = new File(cannotDeleteParent, "child");
  try {
    assumeTrue(cannotDeleteChild.createNewFile());
    assumeTrue(cannotDeleteParent.setWritable(false));
    assumeTrue(cannotDeleteChild.setWritable(false));
    FileUtils.deleteDirectoryQuietly(cannotDeleteParent);
  }
  finally {
    //noinspection ResultOfMethodCallIgnored
    cannotDeleteParent.setWritable(true);
    //noinspection ResultOfMethodCallIgnored
    cannotDeleteChild.setWritable(true);
  }
}
origin: apache/flink

@Test
public void testRenameFileWithNoAccess() throws IOException {
  final FileSystem fs = FileSystem.getLocalFileSystem();
  final File srcFile = temporaryFolder.newFile("someFile.txt");
  final File destFile = new File(temporaryFolder.newFolder(), "target");
  // we need to make the file non-modifiable so that the rename fails
  Assume.assumeTrue(srcFile.getParentFile().setWritable(false, false));
  Assume.assumeTrue(srcFile.setWritable(false, false));
  try {
    final Path srcFilePath = new Path(srcFile.toURI());
    final Path destFilePath = new Path(destFile.toURI());
    // this cannot succeed because the source folder has no permission to remove the file
    assertFalse(fs.rename(srcFilePath, destFilePath));
  }
  finally {
    // make sure we give permission back to ensure proper cleanup
    //noinspection ResultOfMethodCallIgnored
    srcFile.getParentFile().setWritable(true, false);
    //noinspection ResultOfMethodCallIgnored
    srcFile.setWritable(true, false);
  }
}
origin: apache/incubator-druid

@Test
public void testPushCannotCreateDirectory() throws IOException
{
 exception.expect(IOException.class);
 exception.expectMessage("Unable to create directory");
 config.storageDirectory = new File(config.storageDirectory, "xxx");
 Assert.assertTrue(config.storageDirectory.mkdir());
 config.storageDirectory.setWritable(false);
 localDataSegmentPusher.push(dataSegmentFiles, dataSegment, false);
}
origin: apache/flink

@Test
public void testDeleteDirectory() throws Exception {
  // deleting a non-existent file should not cause an error
  File doesNotExist = new File(tmp.newFolder(), "abc");
  FileUtils.deleteDirectory(doesNotExist);
  // deleting a write protected file should throw an error
  File cannotDeleteParent = tmp.newFolder();
  File cannotDeleteChild = new File(cannotDeleteParent, "child");
  try {
    assumeTrue(cannotDeleteChild.createNewFile());
    assumeTrue(cannotDeleteParent.setWritable(false));
    assumeTrue(cannotDeleteChild.setWritable(false));
    FileUtils.deleteDirectory(cannotDeleteParent);
    fail("this should fail with an exception");
  }
  catch (AccessDeniedException ignored) {
    // this is expected
  }
  finally {
    //noinspection ResultOfMethodCallIgnored
    cannotDeleteParent.setWritable(true);
    //noinspection ResultOfMethodCallIgnored
    cannotDeleteChild.setWritable(true);
  }
}
origin: voldemort/voldemort

@Test
public void testMkDir() {
  File tempDir = new File(System.getProperty("java.io.tmpdir"), "temp"
                                 + System.currentTimeMillis());
  // Working case
  Utils.mkdirs(tempDir);
  assertTrue(tempDir.exists());
  // Exists & writable false
  tempDir.setWritable(false);
  try {
    Utils.mkdirs(tempDir);
    fail("Mkdir should have thrown an exception");
  } catch(VoldemortException e) {}
}
origin: apache/incubator-druid

@Test
public void testPushTaskLogDirCreationFails() throws Exception
{
 final File tmpDir = temporaryFolder.newFolder();
 final File logDir = new File(tmpDir, "druid/logs");
 final File logFile = new File(tmpDir, "log");
 Files.write("blah", logFile, StandardCharsets.UTF_8);
 if (!tmpDir.setWritable(false)) {
  throw new RuntimeException("failed to make tmp dir read-only");
 }
 final TaskLogs taskLogs = new FileTaskLogs(new FileTaskLogsConfig(logDir));
 expectedException.expect(IOException.class);
 expectedException.expectMessage("Unable to create task log dir");
 taskLogs.pushTaskLog("foo", logFile);
}
origin: ehcache/ehcache3

@Test
public void testFailsIfDirectoryDoesNotExistsAndIsNotCreated() throws IOException {
 assumeTrue(testFolder.setWritable(false));
 try {
  File f = new File(testFolder, "notallowed");
  try {
   final DefaultLocalPersistenceService service = new DefaultLocalPersistenceService(new DefaultPersistenceConfiguration(f));
   service.start(null);
   fail("Expected IllegalArgumentException");
  } catch(IllegalArgumentException e) {
   assertThat(e.getMessage(), equalTo("Directory couldn't be created: " + f.getAbsolutePath()));
  }
 } finally {
  testFolder.setWritable(true);
 }
}
origin: cSploit/android

inFile = new File(mCurrentTask.path);
total = inFile.length();
counter = new CountingInputStream(new FileInputStream(inFile));
old_percentage = -1;
f = new File(mCurrentTask.outputDir);
if (f.exists() && f.isDirectory() && (list = f.listFiles()) != null && list.length > 2)
 wipe();
 f = new File(mCurrentTask.outputDir, name);
 if(!f.setWritable(w, true)) {
  Logger.warning(String.format("cannot set writable permission of '%s'",name));
origin: apache/nifi

@Test
public void testMoveOnCompleteWithParentOfTargetDirNotAccessible() throws IOException {
  final File sourceFile = new File("target/1.txt");
  final byte[] content = "Hello, World!".getBytes();
  Files.write(sourceFile.toPath(), content, StandardOpenOption.CREATE);
  final String moveTargetParent = "target/fetch-file";
  final String moveTarget = moveTargetParent + "/move-target";
  final TestRunner runner = TestRunners.newTestRunner(new FetchFile());
  runner.setProperty(FetchFile.FILENAME, sourceFile.getAbsolutePath());
  runner.setProperty(FetchFile.COMPLETION_STRATEGY, FetchFile.COMPLETION_MOVE.getValue());
  runner.assertNotValid();
  runner.setProperty(FetchFile.MOVE_DESTINATION_DIR, moveTarget);
  runner.assertValid();
  // Make the parent of move-target non-writable and non-readable
  final File moveTargetParentDir = new File(moveTargetParent);
  moveTargetParentDir.mkdirs();
  moveTargetParentDir.setReadable(false);
  moveTargetParentDir.setWritable(false);
  try {
    runner.enqueue(new byte[0]);
    runner.run();
    runner.assertAllFlowFilesTransferred(FetchFile.REL_FAILURE, 1);
    runner.getFlowFilesForRelationship(FetchFile.REL_FAILURE).get(0).assertContentEquals("");
    assertTrue(sourceFile.exists());
  } finally {
    moveTargetParentDir.setReadable(true);
    moveTargetParentDir.setWritable(true);
  }
}
origin: apache/nifi

@Test
public void testMoveOnCompleteWithTargetExistsButNotWritable() throws IOException {
  final File sourceFile = new File("target/1.txt");
  final byte[] content = "Hello, World!".getBytes();
  Files.write(sourceFile.toPath(), content, StandardOpenOption.CREATE);
  final TestRunner runner = TestRunners.newTestRunner(new FetchFile());
  runner.setProperty(FetchFile.FILENAME, sourceFile.getAbsolutePath());
  runner.setProperty(FetchFile.COMPLETION_STRATEGY, FetchFile.COMPLETION_MOVE.getValue());
  runner.assertNotValid();
  runner.setProperty(FetchFile.MOVE_DESTINATION_DIR, "target/move-target");
  runner.assertValid();
  final File destDir = new File("target/move-target");
  if (!destDir.exists()) {
    destDir.mkdirs();
  }
  destDir.setWritable(false);
  assertTrue(destDir.exists());
  assertFalse(destDir.canWrite());
  final File destFile = new File(destDir, sourceFile.getName());
  runner.enqueue(new byte[0]);
  runner.run();
  runner.assertAllFlowFilesTransferred(FetchFile.REL_FAILURE, 1);
  runner.getFlowFilesForRelationship(FetchFile.REL_FAILURE).get(0).assertContentEquals("");
  assertTrue(sourceFile.exists());
  assertFalse(destFile.exists());
}
origin: apache/incubator-druid

final StorageLocationConfig locationConfig = new StorageLocationConfig();
final File localStorageFolder = tmpFolder.newFolder("local_storage_folder");
localStorageFolder.setWritable(true);
locationConfig.setPath(localStorageFolder);
locationConfig.setMaxSize(10L);
final StorageLocationConfig locationConfig2 = new StorageLocationConfig();
final File localStorageFolder2 = tmpFolder.newFolder("local_storage_folder2");
localStorageFolder2.setWritable(true);
locationConfig2.setPath(localStorageFolder2);
locationConfig2.setMaxSize(10L);
final File localSegmentFile = new File(
  segmentSrcFolder,
  "test_segment_loader/2014-10-20T00:00:00.000Z_2014-10-21T00:00:00.000Z/2015-05-27T03:38:35.683Z/0"
);
localSegmentFile.mkdirs();
final File indexZip = new File(localSegmentFile, "index.zip");
indexZip.createNewFile();
final File localSegmentFile2 = new File(
  segmentSrcFolder,
  "test_segment_loader/2014-11-20T00:00:00.000Z_2014-11-21T00:00:00.000Z/2015-05-27T03:38:35.683Z/0"
java.ioFilesetWritable

Javadoc

Equivalent to setWritable(writable, true).

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

  • Parsing JSON documents to java classes using gson
  • setScale (BigDecimal)
  • notifyDataSetChanged (ArrayAdapter)
  • scheduleAtFixedRate (Timer)
  • Thread (java.lang)
    A thread is a thread of execution in a program. The Java Virtual Machine allows an application to ha
  • Arrays (java.util)
    This class contains various methods for manipulating arrays (such as sorting and searching). This cl
  • Map (java.util)
    A Map is a data structure consisting of a set of keys and values in which each key is mapped to a si
  • TimeZone (java.util)
    TimeZone represents a time zone offset, and also figures out daylight savings. Typically, you get a
  • Semaphore (java.util.concurrent)
    A counting semaphore. Conceptually, a semaphore maintains a set of permits. Each #acquire blocks if
  • FileUtils (org.apache.commons.io)
    General file manipulation utilities. Facilities are provided in the following areas: * writing to a
  • Top 17 Plugins for Android Studio
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

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