本文整理汇总了Java中java.io.File.setExecutable方法的典型用法代码示例。如果您正苦于以下问题:Java File.setExecutable方法的具体用法?Java File.setExecutable怎么用?Java File.setExecutable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.io.File
的用法示例。
在下文中一共展示了File.setExecutable方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: prepareNode
import java.io.File; //导入方法依赖的package包/类
public void prepareNode(Context context, String dataDir) {
InputStream nodeBinary = null;
try {
nodeBinary = context.getResources().openRawResource(R.raw.bin_node_v710);
String nodeFilename = String.format("%s/node", dataDir);
File nodeFile = new File(nodeFilename);
if (nodeFile.exists()) {
return;
}
nodeFile.createNewFile();
InputStreamReader reader = new InputStreamReader(nodeBinary);
FileOutputStream writer = new FileOutputStream(nodeFile);
byte[] binary = new byte[(int)(nodeBinary.available())];
nodeBinary.read(binary);
writer.write(binary);
writer.flush();
writer.close();
nodeFile.setExecutable(true, true);
nodeBinary.close();
} catch (Exception e) {
Log.e(TAG, "Cannot create binary file for \"node\"");
}
}
示例2: maybePreCreateFile
import java.io.File; //导入方法依赖的package包/类
private void maybePreCreateFile() {
try {
File sharedPrefsFolder = new File(mContext.getDataDir().getAbsolutePath() + "/shared_prefs");
if (!sharedPrefsFolder.exists()) {
sharedPrefsFolder.mkdir();
sharedPrefsFolder.setExecutable(true, false);
sharedPrefsFolder.setReadable(true, false);
}
File f = new File(sharedPrefsFolder.getAbsolutePath() + "/" + mPrefsName + ".xml");
if (!f.exists()) {
f.createNewFile();
f.setReadable(true, false);
}
} catch (Exception e) {
Log.e("EffEnhc", "Error pre-creating prefs file " + mPrefsName + ": " + e.getMessage());
}
}
示例3: TEESClassifyExternal
import java.io.File; //导入方法依赖的package包/类
private TEESClassifyExternal(ProcessingContext<Corpus> ctx) throws IOException {
super();
this.ctx = ctx;
File tmp = getTempDir(ctx);
baseDir = tmp;
this.input = new OutputFile(tmp.getAbsolutePath(), "tees-o" + ".xml");
this.outputStem = "tees-i";
//
script = new File(tmp, "classify.sh");
// same ClassLoader as this class
try (InputStream is = TEESTrain.class.getResourceAsStream("classify.sh")) {
Files.copy(is, script, 1024, true);
}
script.setExecutable(true);
}
示例4: GeniaTaggerExternal
import java.io.File; //导入方法依赖的package包/类
public GeniaTaggerExternal(ProcessingContext<Corpus> ctx, Corpus corpus, File tmpDir) throws IOException {
super();
this.ctx = ctx;
this.evalCtx = new EvaluationContext(getLogger(ctx));
script = new File(tmpDir, "genia.sh");
// same ClassLoader as this class
try (InputStream is = GeniaTagger.class.getResourceAsStream("genia.sh")) {
Files.copy(is, script, 1024, true);
}
script.setExecutable(true);
GeniaTaggerResolvedObjects resObj = getResolvedObjects();
input = new OutputFile(tmpDir, "corpus.txt");
TargetStream target = new FileTargetStream(geniaCharset, input);
PrintStream ps = target.getPrintStream();
for (Annotation sent : Iterators.loop(getSentenceIterator(evalCtx, corpus, resObj.getDocumentFilter(), resObj.getSectionFilter(), resObj.sentenceFilter)))
writeSentence(sent, ps);
ps.close();
output = new InputFile(tmpDir, "corpus.genia");
}
示例5: 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;
}
示例6: TEESTrainExternal
import java.io.File; //导入方法依赖的package包/类
private TEESTrainExternal(ProcessingContext<Corpus> ctx) throws IOException {
super();
this.ctx = ctx;
File tmp = getTempDir(ctx);
baseDir = tmp;
this.trainInput = new OutputFile(tmp.getAbsolutePath(), "train-o" + ".xml");
this.devInput = new OutputFile(tmp.getAbsolutePath(), "devel-o" + ".xml");
this.testInput = new OutputFile(tmp.getAbsolutePath(), "test-o" + ".xml");
script = new File(tmp, "train.sh");
// same ClassLoader as this class
try (InputStream is = TEESTrain.class.getResourceAsStream("train.sh")) {
Files.copy(is, script, 1024, true);
}
script.setExecutable(true);
}
示例7: createFile
import java.io.File; //导入方法依赖的package包/类
public static void createFile ( final File file, final InputStream resource, final IProgressMonitor monitor, final boolean exec ) throws Exception
{
file.getParentFile ().mkdirs ();
try
{
try ( FileOutputStream fos = new FileOutputStream ( file ) )
{
ByteStreams.copy ( resource, fos );
}
file.setExecutable ( exec );
}
finally
{
resource.close ();
}
}
示例8: Ab3PExternal
import java.io.File; //导入方法依赖的package包/类
private Ab3PExternal(ProcessingContext<Corpus> ctx, Corpus corpus) throws IOException {
logger = getLogger(ctx);
File tmpDir = getTempDir(ctx);
scriptFile = new File(tmpDir, "script.sh");
inputFile = new File(tmpDir, "input.txt");
outputFile = new File(tmpDir, "output.txt");
// same ClassLoader as this class
try (InputStream is = Ab3P.class.getResourceAsStream("script.sh")) {
Files.copy(is, scriptFile, 1024, true);
scriptFile.setExecutable(true);
}
EvaluationContext evalCtx = new EvaluationContext(logger);
try (PrintStream ps = new PrintStream(inputFile)) {
for (Document doc : Iterators.loop(documentIterator(evalCtx, corpus))) {
for (Section sec : Iterators.loop(sectionIterator(evalCtx, doc))) {
String rawContents = sec.getContents();
String lineContents = rawContents.replace('\n', ' ').trim();
ps.println(lineContents);
ps.println();
}
}
}
}
示例9: setPermissions
import java.io.File; //导入方法依赖的package包/类
/**
* Recursive set permissions to directory
*
* @param path path to directory
*/
private static void setPermissions(File path) {
if (path == null) return;
if (path.exists()) {
path.setReadable(true, false);
path.setExecutable(true, false);
File[] list = path.listFiles();
if (list == null) return;
for (File f : list) {
if (f.isDirectory()) setPermissions(f);
f.setReadable(true, false);
f.setExecutable(true, false);
}
}
}
示例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: unzip
import java.io.File; //导入方法依赖的package包/类
public static void unzip(File zipFile, File destination)
throws IOException {
ZipFile zip = new ZipFile(zipFile);
try {
Enumeration<ZipArchiveEntry> e = zip.getEntries();
while (e.hasMoreElements()) {
ZipArchiveEntry entry = e.nextElement();
File file = new File(destination, entry.getName());
if (entry.isDirectory()) {
file.mkdirs();
} else {
InputStream is = zip.getInputStream(entry);
File parent = file.getParentFile();
if (parent != null && parent.exists() == false) {
parent.mkdirs();
}
FileOutputStream os = new FileOutputStream(file);
try {
IOUtils.copy(is, os);
} finally {
os.close();
is.close();
}
file.setLastModified(entry.getTime());
int mode = entry.getUnixMode();
if ((mode & EXEC_MASK) != 0) {
if (!file.setExecutable(true)) {
}
}
}
}
} finally {
ZipFile.closeQuietly(zip);
}
}
示例12: pythonInit
import java.io.File; //导入方法依赖的package包/类
private static void pythonInit(){
if(FileUtils.exists(sXndroidFile + "/python/bin/python"))
return;
if(!unzipRawFile(R.raw.python, sXndroidFile))
AppModel.fatalError("prepare python fail");
// test();
File[] files = new File(sXndroidFile + "/python/bin").listFiles();
if(files == null){
LogUtils.e("fail to list python/bin");
}else {
for (File binFile : files) {
binFile.setExecutable(true, false);
}
}
}
示例13: getResource
import java.io.File; //导入方法依赖的package包/类
/**
* Writes out the given resource as a temp file and returns the absolute path.
* Caches the location of the files, so we can reuse them.
*
* @param resourcePath the name of the resource
*/
static synchronized String getResource(String resourcePath) {
try {
File file = resources.get(resourcePath);
if (file == null) {
String basename = PathUtil.basename(resourcePath);
String prefix;
String suffix;
int lastDot = basename.lastIndexOf(".");
if (lastDot != -1) {
prefix = basename.substring(0, lastDot);
suffix = basename.substring(lastDot);
} else {
prefix = basename;
suffix = "";
}
while (prefix.length() < 3) {
prefix = prefix + "_";
}
file = File.createTempFile(prefix, suffix);
file.setExecutable(true);
file.deleteOnExit();
file.getParentFile().mkdirs();
Files.copy(Resources.newInputStreamSupplier(Compiler.class.getResource(resourcePath)),
file);
resources.put(resourcePath, file);
}
return file.getAbsolutePath();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
示例14: runUsingDefaultUser
import java.io.File; //导入方法依赖的package包/类
public String runUsingDefaultUser ( String name, String[] lines )
throws IOException {
File scriptWithPermissions = Application.getStagingFile(
"/temp/" + name + "-" + System.currentTimeMillis() + ".sh" );
scriptWithPermissions.getParentFile().mkdirs();
List<String> script = Arrays.asList( lines );
Files.write( scriptWithPermissions.toPath(), script, Charset.forName( "UTF-8" ) );
boolean ableToSet = scriptWithPermissions.setExecutable( true );
if ( !ableToSet ) {
logger.warn( "Unable to set execute permisions on : {}", scriptWithPermissions );
}
List<String> parmList = new ArrayList<String>();
parmList.add( "bash" );
parmList.add( "-c" );
parmList.add( scriptWithPermissions.getAbsolutePath() );
String scriptOutput = "\n" + executeString( null, parmList );
scriptWithPermissions.delete();
logger.debug( "Script Output; {}", scriptOutput );
// strip off script info
int tokenIndex = scriptOutput.indexOf( OUTPUT_TOKEN );
if ( tokenIndex == -1 ) {
tokenIndex = 0;
} else {
tokenIndex += OUTPUT_TOKEN.length();
}
return scriptOutput.substring( tokenIndex );
}
示例15: runUsingRootUser
import java.io.File; //导入方法依赖的package包/类
public String runUsingRootUser ( String name, String[] lines )
throws IOException {
File scriptWithPermissions = Application.getStagingFile(
"/temp/" + name + "-" + System.currentTimeMillis() + ".sh" );
scriptWithPermissions.setExecutable( true );
scriptWithPermissions.getParentFile().mkdirs();
List<String> script = Arrays.asList( lines );
Files.write( scriptWithPermissions.toPath(), script, Charset.forName( "UTF-8" ) );
boolean ableToSet = scriptWithPermissions.setExecutable( true );
if ( !ableToSet ) {
logger.warn( "Unable to set execute permisions on : {}", scriptWithPermissions );
}
String scriptOutput = runUsingRootUser( scriptWithPermissions, null );
scriptWithPermissions.delete();
logger.debug( "Script Output; {}", scriptOutput );
// strip off script info
int tokenIndex = scriptOutput.indexOf( OUTPUT_TOKEN );
if ( tokenIndex == -1 ) {
tokenIndex = 0;
} else {
tokenIndex += OUTPUT_TOKEN.length();
}
return scriptOutput.substring( tokenIndex );
}