當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。