当前位置: 首页>>代码示例>>Java>>正文


Java File.getParent方法代码示例

本文整理汇总了Java中java.io.File.getParent方法的典型用法代码示例。如果您正苦于以下问题:Java File.getParent方法的具体用法?Java File.getParent怎么用?Java File.getParent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.io.File的用法示例。


在下文中一共展示了File.getParent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: build

import java.io.File; //导入方法依赖的package包/类
private void build(File tmpDir, File js) throws Exception {
    File outApk = new File(js.getParent(), js.getName() + ".apk");
    InputStream inApk = getAssets().open("template.apk");
    ApkBuilder apkBuilder = new ApkBuilder(inApk, outApk, tmpDir.getPath())
            .prepare();
    apkBuilder.editManifest()
            .setVersionCode(5000)
            .setVersionName("1.2.3")
            .setAppName("Hello")
            .setPackageName("com.stardust.xxx")
            .commit();
    apkBuilder.replaceFile("assets/script.js", js.getPath())
            .setArscPackageName("com.stardust.xxx")
            .build()
            .sign();
}
 
开发者ID:hyb1996,项目名称:Auto.js-ApkBuilder,代码行数:17,代码来源:MainActivity.java

示例2: rename

import java.io.File; //导入方法依赖的package包/类
/**
 * 重命名文件
 *
 * @param file    文件
 * @param newName 新名称
 * @return {@code true}: 重命名成功<br>{@code false}: 重命名失败
 */
public static boolean rename(final File file, final String newName) {
	// 文件为空返回false
	if (file == null) {
		return false;
	}
	// 文件不存在返回false
	if (!file.exists()) {
		return false;
	}
	// 新的文件名为空返回false
	if (isSpace(newName)) {
		return false;
	}
	// 如果文件名没有改变返回true
	if (newName.equals(file.getName())) {
		return true;
	}
	File newFile = new File(file.getParent() + File.separator + newName);
	// 如果重命名的文件已存在返回false
	return !newFile.exists()
			&& file.renameTo(newFile);
}
 
开发者ID:MobClub,项目名称:BBSSDK-for-Android,代码行数:30,代码来源:FileUtils.java

示例3: makeParentDirectories

import java.io.File; //导入方法依赖的package包/类
public void makeParentDirectories(File f) {

        String parent = f.getParent();

        if (parent != null) {
            new File(parent).mkdirs();
        } else {

            // workaround for jdk 1.1 bug (returns null when there is a parent)
            parent = f.getPath();

            int index = parent.lastIndexOf('/');

            if (index > 0) {
                parent = parent.substring(0, index);

                new File(parent).mkdirs();
            }
        }
    }
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:21,代码来源:FileUtil.java

示例4: doZipAlign

import java.io.File; //导入方法依赖的package包/类
public static synchronized File doZipAlign(final AndroidBuilder androidBuilder, Project project, final File apkFile) {

        final File zipalignedFile = new File(apkFile.getParent(), apkFile.getName().replace(".apk", "-zipaligned.apk"));

        project.exec(new Action<ExecSpec>() {
            @Override
            public void execute(ExecSpec execSpec) {

                String path = androidBuilder.getTargetInfo()
                        .getBuildTools().getPath(ZIP_ALIGN);
                execSpec.executable(new File(path));
                execSpec.args("-f", "4");
                execSpec.args(apkFile);
                execSpec.args(zipalignedFile);
            }
        });

        return zipalignedFile;
    }
 
开发者ID:alibaba,项目名称:atlas,代码行数:20,代码来源:ZipAlignUtils.java

示例5: getUsableDataBase

import java.io.File; //导入方法依赖的package包/类
/**
 * Returns a usable database with the given name. If a database with this name
 * already exists, it is returned. Otherwise created with the given SQL create
 * query.
 */
protected static SQLiteDatabase getUsableDataBase(String dbName,
    String sqlCreateQuery) {
  File dbFile = getPathToDb(dbName);

  File fileDirectory = new File(dbFile.getParent());
  if (!fileDirectory.exists()) {
    // Make sure the path for the file exists, before creating the
    // database.
    fileDirectory.mkdirs();
  }
  Log.d(TAG, "DB Path: " + dbFile.getAbsolutePath());
  boolean initDb = !dbFile.exists();
  try {
    SQLiteDatabase result = SQLiteDatabase.openOrCreateDatabase(dbFile, null);

    if (initDb) {
      result.execSQL(sqlCreateQuery);
    }

    return result;
  } catch (SQLiteException ex) {
    Log.w(TAG, "Could not open or image database.");
    return null;
  }
}
 
开发者ID:sdrausty,项目名称:buildAPKsSamples,代码行数:31,代码来源:AbstractPicViewDatabase.java

示例6: readMesasurementFilesFromSafe

import java.io.File; //导入方法依赖的package包/类
/**
 * Return the mesaurements
 * 
 * @return
 */
public void readMesasurementFilesFromSafe() {
	XPathExpression<Element> expr = xFactory
			.compile(
					"/xfdu:XFDU/dataObjectSection/dataObject[@repID='s1Level1ProductSchema']/byteStream/fileLocation",
					Filters.element(), null, xfdu);

	List<Element> values = expr.evaluate(safe);
	this.measurements=new File[values.size()];
	
	File safefile = new File(safePath);
	String measurementPath = safefile.getParent() + "/measurement";

	for (int i = 0; i < values.size(); i++) {
		Element e = values.get(i);
		String href = e.getAttributeValue("href");
		if (href.startsWith("./"))
			href = href.substring(2);
		measurements[i] = new File(measurementPath + "/" + href);
		System.out.println(measurements[i]);
	}

}
 
开发者ID:ec-europa,项目名称:sumo,代码行数:28,代码来源:SumoSafeReader.java

示例7: createFileParents

import java.io.File; //导入方法依赖的package包/类
public static boolean createFileParents(File file){
	if(file.exists()){
		return true;
	}
	File parent = new File(file.getParent());
	if(parent.exists()){
		return true;
	}
	try{
		parent.mkdirs();
	}catch(Exception e){
		return false;
	}
	return true;
}
 
开发者ID:hotpads,项目名称:datarouter,代码行数:16,代码来源:FileTool.java

示例8: compileTestFile

import java.io.File; //导入方法依赖的package包/类
protected File compileTestFile(File f, String testClass, String... extraParams) {
    List<String> options = new ArrayList<>();
    options.addAll(Arrays.asList(extraParams));
    options.add(f.getPath());
    int rc = com.sun.tools.javac.Main.compile(options.toArray(new String[options.size()]));
    if (rc != 0)
        throw new Error("compilation failed. rc=" + rc);
    String path = f.getParent() != null ? f.getParent() : "";
    return new File(path, format("%s.class", testClass));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:Driver.java

示例9: onActivityResult

import java.io.File; //导入方法依赖的package包/类
@Override
protected void onActivityResult(final int requestCode, final int resultCode, @NonNull final Intent returnIntent)
{
	switch (requestCode)
	{
		case REQUEST_FILE_CODE:
			if (resultCode == AppCompatActivity.RESULT_OK)
			{
				final Uri fileUri = returnIntent.getData();
				if (fileUri == null)
				{
					break;
				}

				Toast.makeText(this, fileUri.toString(), Toast.LENGTH_SHORT).show();
				final File file = new File(fileUri.getPath());
				final String parent = file.getParent();
				final File parentFile = new File(parent);
				final Uri parentUri = Uri.fromFile(parentFile);
				final String query = file.getName();
				String base = parentUri.toString();
				if (base != null && !base.endsWith("/"))
				{
					base += '/';
				}
				Settings.save(this, query, base);

				updateButton();

				// query
				// query();
			}
			break;
		default:
			break;
	}
	super.onActivityResult(requestCode, resultCode, returnIntent);
}
 
开发者ID:1313ou,项目名称:TreebolicPlugins,代码行数:39,代码来源:MainActivity.java

示例10: writeTags

import java.io.File; //导入方法依赖的package包/类
/**
 * Write tags to file
 * @param file File to write
 * @param tag NBT tag to write
 * @throws IOException If writing failed
 */
public static void writeTags(File file, NBTTagCompound tag) throws IOException {
    if (file.getParentFile() != null && !file.getParentFile().exists()) {
        if (!file.getParentFile().mkdirs()) {
            throw new IOException("Can't create path: " + file.getParent());
        }
    }
    try (FileOutputStream fos = new FileOutputStream(file)) {
        CompressedStreamTools.writeCompressed(tag, fos);
    }
}
 
开发者ID:ternsip,项目名称:StructPro,代码行数:17,代码来源:Utils.java

示例11: setFile

import java.io.File; //导入方法依赖的package包/类
public void setFile(File imageFile) {
    displayName = imageFile.getPath();
    try {
        dat = new RandomAccessFile(imageFile, "r");
        directory = imageFile.getParent();
    } catch (Exception ex) {
        dispose();
        logger.error("Cannot access the file ",ex);
    }
}
 
开发者ID:ec-europa,项目名称:sumo,代码行数:11,代码来源:Radarsat1Image.java

示例12: invokeNbExecAndCreateCluster

import java.io.File; //导入方法依赖的package包/类
private void invokeNbExecAndCreateCluster(File workDir, StringBuffer sb, String... args) throws Exception {
        URL u = Lookup.class.getProtectionDomain().getCodeSource().getLocation();
        File f = Utilities.toFile(u.toURI());
        assertTrue("file found: " + f, f.exists());
        File nbexec = org.openide.util.Utilities.isWindows() ? new File(f.getParent(), "nbexec.exe") : new File(f.getParent(), "nbexec");
        assertTrue("nbexec found: " + nbexec, nbexec.exists());
        LOG.log(Level.INFO, "nbexec: {0}", nbexec);

        URL tu = NewClustersRebootCallback.class.getProtectionDomain().getCodeSource().getLocation();
        File testf = Utilities.toFile(tu.toURI());
        assertTrue("file found: " + testf, testf.exists());

        LinkedList<String> allArgs = new LinkedList<String>(Arrays.asList(args));
        allArgs.addFirst("-J-Dnetbeans.mainclass=" + NewClustersRebootCallback.class.getName());
        allArgs.addFirst(System.getProperty("java.home"));
        allArgs.addFirst("--jdkhome");
        allArgs.addFirst(getWorkDirPath());
        allArgs.addFirst("--userdir");
        allArgs.addFirst(testf.getPath());
        allArgs.addFirst("-cp:p");
        allArgs.addFirst("--nosplash");

        if (!org.openide.util.Utilities.isWindows()) {
            allArgs.addFirst(nbexec.getPath());
            allArgs.addFirst("-x");
            allArgs.addFirst("/bin/sh");
        } else {
            allArgs.addFirst(nbexec.getPath());
        }
        LOG.log(Level.INFO, "About to execute {0}@{1}", new Object[]{allArgs, workDir});
        Process p = Runtime.getRuntime().exec(allArgs.toArray(new String[0]), new String[0], workDir);
        LOG.log(Level.INFO, "Process created {0}", p);
        int res = readOutput(sb, p);
        LOG.log(Level.INFO, "Output read: {0}", res);
        String output = sb.toString();
//        System.out.println("nbexec output is: " + output);
        assertEquals("Execution is ok: " + output, 0, res);
    }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:39,代码来源:NewClustersRebootTest.java

示例13: rename

import java.io.File; //导入方法依赖的package包/类
public static boolean rename(File file, String newName) {
    // 文件为空返回false
    if (file == null) return false;
    // 文件不存在返回false
    if (!file.exists()) return false;
    // 新的文件名为空返回false
    if (isSpace(newName)) return false;
    // 如果文件名没有改变返回true
    if (newName.equals(file.getName())) return true;
    File newFile = new File(file.getParent() + File.separator + newName);
    // 如果重命名的文件已存在返回false
    return !newFile.exists()
            && file.renameTo(newFile);
}
 
开发者ID:ChangsenLai,项目名称:codedemos,代码行数:15,代码来源:FileUtil.java

示例14: run

import java.io.File; //导入方法依赖的package包/类
private void run(File workDir, String... args) throws Exception {
    URL u = Lookup.class.getProtectionDomain().getCodeSource().getLocation();
    File f = Utilities.toFile(u.toURI());
    assertTrue("file found: " + f, f.exists());
    File nbexec = Utilities.isWindows() ? new File(f.getParent(), "nbexec.exe") : new File(f.getParent(), "nbexec");
    assertTrue("nbexec found: " + nbexec, nbexec.exists());

    URL tu = MainCallback.class.getProtectionDomain().getCodeSource().getLocation();
    File testf = Utilities.toFile(tu.toURI());
    assertTrue("file found: " + testf, testf.exists());
    
    LinkedList<String> allArgs = new LinkedList<String>(Arrays.asList(args));
    allArgs.addFirst("-J-Dnetbeans.mainclass=" + MainCallback.class.getName());
    allArgs.addFirst(System.getProperty("java.home"));
    allArgs.addFirst("--jdkhome");
    allArgs.addFirst(getWorkDirPath());
    allArgs.addFirst("--userdir");
    allArgs.addFirst(testf.getPath());
    allArgs.addFirst("-cp:p");
    
    if (!Utilities.isWindows()) {
        allArgs.addFirst(nbexec.getPath());
        allArgs.addFirst("-x");
        allArgs.addFirst("/bin/sh");
    } else {
        allArgs.addFirst(nbexec.getPath());
    }
    
    StringBuffer sb = new StringBuffer();
    Process p = Runtime.getRuntime().exec(allArgs.toArray(new String[allArgs.size()]), new String[0], workDir);
    int res = readOutput(sb, p);
    
    String output = sb.toString();
    
    assertEquals("Execution is ok: " + output, 0, res);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:37,代码来源:NbExecPassesCorrectlyQuotedArgsTest.java

示例15: createItemAttributes

import java.io.File; //导入方法依赖的package包/类
@Override
protected DirItemAttributes createItemAttributes(final File resource) {
    DirItemAttributes dia = new DirItemAttributes();
    dia.setDirname(resource.getName());
    dia.setItemId(resource.getAbsolutePath());
    dia.setItemName(resource.getName());
    String path = resource.getParent();
    if (path != null) {
        dia.setPath(path);
    }
    dirItems.put(dia.getItemId(), dia);
    return dia;
}
 
开发者ID:HewlettPackard,项目名称:loom,代码行数:14,代码来源:DirSystemUpdater.java


注:本文中的java.io.File.getParent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。