本文整理了Java中java.io.File.setExecutable()
方法的一些代码示例,展示了File.setExecutable()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。File.setExecutable()
方法的具体详情如下:
包路径:java.io.File
类名称:File
方法名:setExecutable
[英]Equivalent to setExecutable(executable, true).
[中]等同于setExecutable(可执行,true)。
代码示例来源:origin: iBotPeaches/Apktool
public static String getAaptExecutionCommand(String aaptPath, File aapt) throws BrutException {
if (! aaptPath.isEmpty()) {
File aaptFile = new File(aaptPath);
if (aaptFile.canRead() && aaptFile.exists()) {
aaptFile.setExecutable(true);
return aaptFile.getPath();
} else {
throw new BrutException("binary could not be read: " + aaptFile.getAbsolutePath());
}
} else {
return aapt.getAbsolutePath();
}
}
代码示例来源:origin: Qihoo360/XLearning
public static void setPathExecutableRecursively(String path) {
File file = new File(path);
if (!file.exists()) {
LOG.warn("Path " + path + " does not exist!");
return;
}
if (!file.setExecutable(true)) {
LOG.error("Failed to set executable for " + path);
}
if (file.isDirectory()) {
File[] files = file.listFiles();
if (null != files && files.length > 0) {
setPathExecutableRecursively(file.getAbsolutePath());
}
}
}
代码示例来源:origin: ethereum/ethereumj
private void initBundled() throws IOException {
File tmpDir = new File(System.getProperty("java.io.tmpdir"), "solc");
tmpDir.mkdirs();
InputStream is = getClass().getResourceAsStream("/native/" + getOS() + "/solc/file.list");
try (Scanner scanner = new Scanner(is)) {
while (scanner.hasNext()) {
String s = scanner.next();
File targetFile = new File(tmpDir, s);
InputStream fis = getClass().getResourceAsStream("/native/" + getOS() + "/solc/" + 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();
}
}
}
代码示例来源:origin: cSploit/android
/**
* check if the cSploit user can create executable files inside a directory.
* @param dir directory to check
* @return true if can execute files into {@code dir}, false otherwise
*/
private boolean user(String dir) {
String tmpname;
File tmpfile = null;
if(dir==null)
return false;
tmpfile = new File(dir);
try {
if(!tmpfile.exists())
tmpfile.mkdirs();
do {
tmpname = UUID.randomUUID().toString();
} while((tmpfile = new File(dir, tmpname)).exists());
tmpfile.createNewFile();
return (tmpfile.canExecute() || tmpfile.setExecutable(true, false));
} catch (IOException e) {
Logger.warning(String.format("cannot create files over '%s'",dir));
} finally {
if(tmpfile!=null && tmpfile.exists())
tmpfile.delete();
}
return false;
}
代码示例来源:origin: prestodb/presto
private void copyExecutable(String name, File target)
throws IOException
{
byte[] bytes = toByteArray(Resources.getResource(getClass(), name));
Path path = target.toPath().resolve(new File(name).getName());
Files.write(path, bytes);
if (!path.toFile().setExecutable(true)) {
throw new IOException("failed to make executable: " + path);
}
}
}
代码示例来源:origin: apache/flink
private static void internalCopyFile(Path sourcePath, Path targetPath, boolean executable, FileSystem sFS, FileSystem tFS) throws IOException {
try (FSDataOutputStream lfsOutput = tFS.create(targetPath, FileSystem.WriteMode.NO_OVERWRITE); FSDataInputStream fsInput = sFS.open(sourcePath)) {
IOUtils.copyBytes(fsInput, lfsOutput);
//noinspection ResultOfMethodCallIgnored
new File(targetPath.toString()).setExecutable(executable);
}
}
代码示例来源:origin: redisson/redisson
File extractedLibFile = new File(targetFolder, extractedLibFileName);
extractedLibFile.setExecutable(true);
if (!success) {
return new File(targetFolder, extractedLibFileName);
代码示例来源:origin: simpligility/android-maven-plugin
sh = new File( "/bin/bash" );
if ( !sh.exists() )
sh = new File( "/usr/bin/bash" );
sh = new File( "/bin/sh" );
file.setExecutable( true );
return filename;
代码示例来源:origin: simpligility/android-maven-plugin
File file = new File( filename );
PrintWriter writer = null;
try
file.setExecutable( true );
return filename;
代码示例来源:origin: termux/termux-app
void handleUrlAndFinish(final String url) {
final File urlOpenerProgramFile = new File(URL_OPENER_PROGRAM);
if (!urlOpenerProgramFile.isFile()) {
showErrorDialogAndQuit("The following file does not exist:\n$HOME/bin/termux-url-opener\n\n"
+ "Create this file as a script or a symlink - it will be called with the shared URL as only argument.");
return;
}
// Do this for the user if necessary:
//noinspection ResultOfMethodCallIgnored
urlOpenerProgramFile.setExecutable(true);
final Uri urlOpenerProgramUri = new Uri.Builder().scheme("file").path(URL_OPENER_PROGRAM).build();
Intent executeIntent = new Intent(TermuxService.ACTION_EXECUTE, urlOpenerProgramUri);
executeIntent.setClass(TermuxFileReceiverActivity.this, TermuxService.class);
executeIntent.putExtra(TermuxService.EXTRA_ARGUMENTS, new String[]{url});
startService(executeIntent);
finish();
}
代码示例来源: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: marytts/marytts
ZipEntry entry = entries.nextElement();
File newFile = new File(maryBase + "/" + entry.getName());
if (entry.isDirectory()) {
System.err.println("Extracting directory: " + entry.getName());
if (newFile.setExecutable(true, false)) {
System.err.println("Setting executable bit on file: " + entry.getName());
代码示例来源:origin: apache/geode
File generate(final File outputDir) throws IOException {
File outputFile = new File(outputDir, generator.getScriptName());
try (BufferedWriter writer = Files.newBufferedWriter(outputFile.toPath())) {
writePreamble(writer);
writeAbout(writer);
writeExistenceTest(writer);
writeRestoreData(writer, outputDir.toPath());
writeIncrementalData(writer);
generator.writeExit(writer);
}
outputFile.setExecutable(true, true);
return outputFile;
}
代码示例来源:origin: eirslett/frontend-maven-plugin
File nodeModulesDirectory = new File(installDirectory, "node_modules");
File oldNpmDirectory = new File(installDirectory, "npm");
File npmDirectory = new File(nodeModulesDirectory, "npm");
try {
if (oldNpmDirectory.isDirectory()) {
File copy = new File(installDirectory, script);
FileUtils.copyFile(scriptFile, copy);
copy.setExecutable(true);
代码示例来源: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/drill
/**
* Copy the standard scripts from source location to the mock distribution
* directory.
*/
private void copyScripts(File sourceDir) throws IOException {
File binDir = new File(testDrillHome, "bin");
for (String script : ScriptUtils.scripts) {
File source = new File(sourceDir, script);
File dest = new File(binDir, script);
copyFile(source, dest);
dest.setExecutable(true);
}
// Create the "magic" wrapper script that simulates the Drillbit and
// captures the output we need for testing.
String wrapper = "wrapper.sh";
File dest = new File(binDir, wrapper);
try (InputStream is = getClass().getResourceAsStream("/" + wrapper)) {
Files.copy(is, dest.toPath(), StandardCopyOption.REPLACE_EXISTING);
}
dest.setExecutable(true);
}
代码示例来源:origin: uber/okbuck
File groovyStarterConf = new File(groovyHome, "groovy-starter.conf");
FileUtil.copyResourceToProject("groovy/conf/groovy-starter.conf", groovyStarterConf);
File groovyc = new File(groovyHome, "groovyc");
new Groovyc().groovyVersion(groovyVersion).render(groovyc);
groovyc.setExecutable(true);
File startGroovy = new File(groovyHome, "startGroovy");
new StartGroovy().groovyVersion(groovyVersion).render(startGroovy);
startGroovy.setExecutable(true);
代码示例来源:origin: eirslett/frontend-maven-plugin
@Override
public void extract(String archive, String destinationDirectory) throws ArchiveExtractionException {
final File archiveFile = new File(archive);
while (entries.hasMoreElements()) {
ZipEntry entry = entries.nextElement();
final File destPath = new File(destinationDirectory + File.separator + entry.getName());
prepDestination(destPath, entry.isDirectory());
if(!entry.isDirectory()){
while (tarEntry != null) {
final File destPath = new File(destinationDirectory + File.separator + tarEntry.getName());
prepDestination(destPath, tarEntry.isDirectory());
if (!destPath.getCanonicalPath().startsWith(destinationDirectory)) {
destPath.createNewFile();
boolean isExecutable = (tarEntry.getMode() & 0100) > 0;
destPath.setExecutable(isExecutable);
代码示例来源:origin: libgdx/libgdx
new File(outputDir, "gradlew").setExecutable(true);
Executor.execute(new File(outputDir), "gradlew.bat", "gradlew", "clean" + parseGradleArgs(builder.modules, gradleArgs), callback);
代码示例来源:origin: konsoletyper/teavm
@Override
public void runTest(TestRun run) throws IOException {
try {
File inputFile = new File(run.getBaseDirectory(), run.getFileName());
String exeName = run.getFileName();
if (exeName.endsWith(".c")) {
File outputFile = new File(run.getBaseDirectory(), exeName);
List<String> compilerOutput = new ArrayList<>();
boolean compilerSuccess = runCompiler(inputFile, outputFile, compilerOutput);
outputFile.setExecutable(true);
runProcess(new ProcessBuilder(outputFile.getPath()).start(), runtimeOutput);
if (!runtimeOutput.isEmpty() && runtimeOutput.get(runtimeOutput.size() - 1).equals("SUCCESS")) {
内容来源于网络,如有侵权,请联系作者删除!