java.io.File.setExecutable()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(9.9k)|赞(0)|评价(0)|浏览(214)

本文整理了Java中java.io.File.setExecutable()方法的一些代码示例,展示了File.setExecutable()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。File.setExecutable()方法的具体详情如下:
包路径:java.io.File
类名称:File
方法名:setExecutable

File.setExecutable介绍

[英]Equivalent to setExecutable(executable, true).
[中]等同于setExecutable(可执行,true)。

代码示例

代码示例来源:origin: iBotPeaches/Apktool

  1. public static String getAaptExecutionCommand(String aaptPath, File aapt) throws BrutException {
  2. if (! aaptPath.isEmpty()) {
  3. File aaptFile = new File(aaptPath);
  4. if (aaptFile.canRead() && aaptFile.exists()) {
  5. aaptFile.setExecutable(true);
  6. return aaptFile.getPath();
  7. } else {
  8. throw new BrutException("binary could not be read: " + aaptFile.getAbsolutePath());
  9. }
  10. } else {
  11. return aapt.getAbsolutePath();
  12. }
  13. }

代码示例来源:origin: Qihoo360/XLearning

  1. public static void setPathExecutableRecursively(String path) {
  2. File file = new File(path);
  3. if (!file.exists()) {
  4. LOG.warn("Path " + path + " does not exist!");
  5. return;
  6. }
  7. if (!file.setExecutable(true)) {
  8. LOG.error("Failed to set executable for " + path);
  9. }
  10. if (file.isDirectory()) {
  11. File[] files = file.listFiles();
  12. if (null != files && files.length > 0) {
  13. setPathExecutableRecursively(file.getAbsolutePath());
  14. }
  15. }
  16. }

代码示例来源:origin: ethereum/ethereumj

  1. private void initBundled() throws IOException {
  2. File tmpDir = new File(System.getProperty("java.io.tmpdir"), "solc");
  3. tmpDir.mkdirs();
  4. InputStream is = getClass().getResourceAsStream("/native/" + getOS() + "/solc/file.list");
  5. try (Scanner scanner = new Scanner(is)) {
  6. while (scanner.hasNext()) {
  7. String s = scanner.next();
  8. File targetFile = new File(tmpDir, s);
  9. InputStream fis = getClass().getResourceAsStream("/native/" + getOS() + "/solc/" + s);
  10. Files.copy(fis, targetFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
  11. if (solc == null) {
  12. // first file in the list denotes executable
  13. solc = targetFile;
  14. solc.setExecutable(true);
  15. }
  16. targetFile.deleteOnExit();
  17. }
  18. }
  19. }

代码示例来源:origin: cSploit/android

  1. /**
  2. * check if the cSploit user can create executable files inside a directory.
  3. * @param dir directory to check
  4. * @return true if can execute files into {@code dir}, false otherwise
  5. */
  6. private boolean user(String dir) {
  7. String tmpname;
  8. File tmpfile = null;
  9. if(dir==null)
  10. return false;
  11. tmpfile = new File(dir);
  12. try {
  13. if(!tmpfile.exists())
  14. tmpfile.mkdirs();
  15. do {
  16. tmpname = UUID.randomUUID().toString();
  17. } while((tmpfile = new File(dir, tmpname)).exists());
  18. tmpfile.createNewFile();
  19. return (tmpfile.canExecute() || tmpfile.setExecutable(true, false));
  20. } catch (IOException e) {
  21. Logger.warning(String.format("cannot create files over '%s'",dir));
  22. } finally {
  23. if(tmpfile!=null && tmpfile.exists())
  24. tmpfile.delete();
  25. }
  26. return false;
  27. }

代码示例来源:origin: prestodb/presto

  1. private void copyExecutable(String name, File target)
  2. throws IOException
  3. {
  4. byte[] bytes = toByteArray(Resources.getResource(getClass(), name));
  5. Path path = target.toPath().resolve(new File(name).getName());
  6. Files.write(path, bytes);
  7. if (!path.toFile().setExecutable(true)) {
  8. throw new IOException("failed to make executable: " + path);
  9. }
  10. }
  11. }

代码示例来源:origin: apache/flink

  1. private static void internalCopyFile(Path sourcePath, Path targetPath, boolean executable, FileSystem sFS, FileSystem tFS) throws IOException {
  2. try (FSDataOutputStream lfsOutput = tFS.create(targetPath, FileSystem.WriteMode.NO_OVERWRITE); FSDataInputStream fsInput = sFS.open(sourcePath)) {
  3. IOUtils.copyBytes(fsInput, lfsOutput);
  4. //noinspection ResultOfMethodCallIgnored
  5. new File(targetPath.toString()).setExecutable(executable);
  6. }
  7. }

代码示例来源:origin: redisson/redisson

  1. File extractedLibFile = new File(targetFolder, extractedLibFileName);
  2. extractedLibFile.setExecutable(true);
  3. if (!success) {
  4. return new File(targetFolder, extractedLibFileName);

代码示例来源:origin: simpligility/android-maven-plugin

  1. sh = new File( "/bin/bash" );
  2. if ( !sh.exists() )
  3. sh = new File( "/usr/bin/bash" );
  4. sh = new File( "/bin/sh" );
  5. file.setExecutable( true );
  6. return filename;

代码示例来源:origin: simpligility/android-maven-plugin

  1. File file = new File( filename );
  2. PrintWriter writer = null;
  3. try
  4. file.setExecutable( true );
  5. return filename;

代码示例来源:origin: termux/termux-app

  1. void handleUrlAndFinish(final String url) {
  2. final File urlOpenerProgramFile = new File(URL_OPENER_PROGRAM);
  3. if (!urlOpenerProgramFile.isFile()) {
  4. showErrorDialogAndQuit("The following file does not exist:\n$HOME/bin/termux-url-opener\n\n"
  5. + "Create this file as a script or a symlink - it will be called with the shared URL as only argument.");
  6. return;
  7. }
  8. // Do this for the user if necessary:
  9. //noinspection ResultOfMethodCallIgnored
  10. urlOpenerProgramFile.setExecutable(true);
  11. final Uri urlOpenerProgramUri = new Uri.Builder().scheme("file").path(URL_OPENER_PROGRAM).build();
  12. Intent executeIntent = new Intent(TermuxService.ACTION_EXECUTE, urlOpenerProgramUri);
  13. executeIntent.setClass(TermuxFileReceiverActivity.this, TermuxService.class);
  14. executeIntent.putExtra(TermuxService.EXTRA_ARGUMENTS, new String[]{url});
  15. startService(executeIntent);
  16. finish();
  17. }

代码示例来源:origin: testcontainers/testcontainers-java

  1. @BeforeClass
  2. public static void setupContent() throws FileNotFoundException {
  3. contentFolder.mkdir();
  4. contentFolder.setReadable(true, false);
  5. contentFolder.setWritable(true, false);
  6. contentFolder.setExecutable(true, false);
  7. File indexFile = new File(contentFolder, "index.html");
  8. indexFile.setReadable(true, false);
  9. indexFile.setWritable(true, false);
  10. indexFile.setExecutable(true, false);
  11. @Cleanup PrintStream printStream = new PrintStream(new FileOutputStream(indexFile));
  12. printStream.println("<html><body>This worked</body></html>");
  13. }

代码示例来源:origin: marytts/marytts

  1. ZipEntry entry = entries.nextElement();
  2. File newFile = new File(maryBase + "/" + entry.getName());
  3. if (entry.isDirectory()) {
  4. System.err.println("Extracting directory: " + entry.getName());
  5. if (newFile.setExecutable(true, false)) {
  6. System.err.println("Setting executable bit on file: " + entry.getName());

代码示例来源:origin: apache/geode

  1. File generate(final File outputDir) throws IOException {
  2. File outputFile = new File(outputDir, generator.getScriptName());
  3. try (BufferedWriter writer = Files.newBufferedWriter(outputFile.toPath())) {
  4. writePreamble(writer);
  5. writeAbout(writer);
  6. writeExistenceTest(writer);
  7. writeRestoreData(writer, outputDir.toPath());
  8. writeIncrementalData(writer);
  9. generator.writeExit(writer);
  10. }
  11. outputFile.setExecutable(true, true);
  12. return outputFile;
  13. }

代码示例来源:origin: eirslett/frontend-maven-plugin

  1. File nodeModulesDirectory = new File(installDirectory, "node_modules");
  2. File oldNpmDirectory = new File(installDirectory, "npm");
  3. File npmDirectory = new File(nodeModulesDirectory, "npm");
  4. try {
  5. if (oldNpmDirectory.isDirectory()) {
  6. File copy = new File(installDirectory, script);
  7. FileUtils.copyFile(scriptFile, copy);
  8. copy.setExecutable(true);

代码示例来源:origin: testcontainers/testcontainers-java

  1. @SuppressWarnings({"Duplicates", "ResultOfMethodCallIgnored"})
  2. @BeforeClass
  3. public static void setupContent() throws FileNotFoundException {
  4. contentFolder.mkdir();
  5. contentFolder.setReadable(true, false);
  6. contentFolder.setWritable(true, false);
  7. contentFolder.setExecutable(true, false);
  8. File indexFile = new File(contentFolder, "index.html");
  9. indexFile.setReadable(true, false);
  10. indexFile.setWritable(true, false);
  11. indexFile.setExecutable(true, false);
  12. @Cleanup PrintStream printStream = new PrintStream(new FileOutputStream(indexFile));
  13. printStream.println("<html><body>This worked</body></html>");
  14. }

代码示例来源:origin: apache/drill

  1. /**
  2. * Copy the standard scripts from source location to the mock distribution
  3. * directory.
  4. */
  5. private void copyScripts(File sourceDir) throws IOException {
  6. File binDir = new File(testDrillHome, "bin");
  7. for (String script : ScriptUtils.scripts) {
  8. File source = new File(sourceDir, script);
  9. File dest = new File(binDir, script);
  10. copyFile(source, dest);
  11. dest.setExecutable(true);
  12. }
  13. // Create the "magic" wrapper script that simulates the Drillbit and
  14. // captures the output we need for testing.
  15. String wrapper = "wrapper.sh";
  16. File dest = new File(binDir, wrapper);
  17. try (InputStream is = getClass().getResourceAsStream("/" + wrapper)) {
  18. Files.copy(is, dest.toPath(), StandardCopyOption.REPLACE_EXISTING);
  19. }
  20. dest.setExecutable(true);
  21. }

代码示例来源:origin: uber/okbuck

  1. File groovyStarterConf = new File(groovyHome, "groovy-starter.conf");
  2. FileUtil.copyResourceToProject("groovy/conf/groovy-starter.conf", groovyStarterConf);
  3. File groovyc = new File(groovyHome, "groovyc");
  4. new Groovyc().groovyVersion(groovyVersion).render(groovyc);
  5. groovyc.setExecutable(true);
  6. File startGroovy = new File(groovyHome, "startGroovy");
  7. new StartGroovy().groovyVersion(groovyVersion).render(startGroovy);
  8. startGroovy.setExecutable(true);

代码示例来源:origin: eirslett/frontend-maven-plugin

  1. @Override
  2. public void extract(String archive, String destinationDirectory) throws ArchiveExtractionException {
  3. final File archiveFile = new File(archive);
  4. while (entries.hasMoreElements()) {
  5. ZipEntry entry = entries.nextElement();
  6. final File destPath = new File(destinationDirectory + File.separator + entry.getName());
  7. prepDestination(destPath, entry.isDirectory());
  8. if(!entry.isDirectory()){
  9. while (tarEntry != null) {
  10. final File destPath = new File(destinationDirectory + File.separator + tarEntry.getName());
  11. prepDestination(destPath, tarEntry.isDirectory());
  12. if (!destPath.getCanonicalPath().startsWith(destinationDirectory)) {
  13. destPath.createNewFile();
  14. boolean isExecutable = (tarEntry.getMode() & 0100) > 0;
  15. destPath.setExecutable(isExecutable);

代码示例来源:origin: libgdx/libgdx

  1. new File(outputDir, "gradlew").setExecutable(true);
  2. Executor.execute(new File(outputDir), "gradlew.bat", "gradlew", "clean" + parseGradleArgs(builder.modules, gradleArgs), callback);

代码示例来源:origin: konsoletyper/teavm

  1. @Override
  2. public void runTest(TestRun run) throws IOException {
  3. try {
  4. File inputFile = new File(run.getBaseDirectory(), run.getFileName());
  5. String exeName = run.getFileName();
  6. if (exeName.endsWith(".c")) {
  7. File outputFile = new File(run.getBaseDirectory(), exeName);
  8. List<String> compilerOutput = new ArrayList<>();
  9. boolean compilerSuccess = runCompiler(inputFile, outputFile, compilerOutput);
  10. outputFile.setExecutable(true);
  11. runProcess(new ProcessBuilder(outputFile.getPath()).start(), runtimeOutput);
  12. if (!runtimeOutput.isEmpty() && runtimeOutput.get(runtimeOutput.size() - 1).equals("SUCCESS")) {

相关文章