Example usage for java.io File getParent

List of usage examples for java.io File getParent

Introduction

In this page you can find the example usage for java.io File getParent.

Prototype

public String getParent() 

Source Link

Document

Returns the pathname string of this abstract pathname's parent, or null if this pathname does not name a parent directory.

Usage

From source file:com.chinamobile.bcbsp.fault.tools.Zip.java

/**
 * get file entry name according to base
 * @param base// www  . j a  v  a  2 s.c om
 *        base to split the total file
 * @param file
 *        file to get the entry
 * @return entry name.
 */
private static String getEntryName(String base, File file) {
    File baseFile = new File(base);
    String filename = file.getPath();
    if (baseFile.getParentFile().getParentFile() == null) {
        return filename.substring(baseFile.getParent().length());
    } // d:/file1 /file2/text.txt
    /*d:/file1/text.txt*/
    return filename.substring(baseFile.getParent().length() + 1);
}

From source file:media_organizer.MediaInspector.java

private static boolean symbolicLink(File file) throws IOException {
    if (file == null) {
        throw new NullPointerException("NULL file object!");
    }/*ww  w  .j a v a  2 s  .  co m*/
    File canonicalFile;
    if (file.getParent() == null) {
        canonicalFile = file;
    } else {
        File canonicalDir = file.getParentFile().getCanonicalFile();
        canonicalFile = new File(canonicalDir, file.getName());
    }
    return !canonicalFile.getCanonicalFile().equals(canonicalFile.getAbsoluteFile());
}

From source file:aurelienribon.texturepackergui.Project.java

public static Project fromFile(File file) throws IOException {
    Project prj = load(FileUtils.readFileToString(file));
    if (!prj.input.equals(""))
        prj.input = new File(file.getParent(), prj.input).getCanonicalPath();
    if (!prj.output.equals(""))
        prj.output = new File(file.getParent(), prj.output).getCanonicalPath();
    return prj;//w  w w.j  a  v a  2s .  co  m
}

From source file:com.bfd.harpc.common.configure.PathUtils.java

/**
 * ???classpathjarjar/*from w w w . j  a  v  a 2  s  . c o  m*/
 * <p>
 * 
 * @return
 * @throws UnsupportedEncodingException
 * @throws URISyntaxException
 */
public static String getAppDir(Class<?> clazz) {
    File f;
    try {
        f = new File(getCodeLocation(clazz).toURI().getPath());
        return f.isFile() ? f.getParent() : f.getPath();
    } catch (URISyntaxException e) {
        throw new RuntimeException(e);
    }

}

From source file:com.taobao.android.builder.tools.BuildHelper.java

public static void writeFileToApk(File destFile, File file, String path) throws IOException {
    File outPutFile = new File(file.getParent(), "temp.apk");
    ZipUtils.addFileToZipFile(file, outPutFile, destFile, path, true);
    FileUtils.deleteQuietly(file);//from  w  w w.j  a  v  a  2 s .  co m
    FileUtils.moveFile(outPutFile, file);
    FileUtils.deleteQuietly(destFile);
}

From source file:com.taobao.android.builder.tools.BuildHelper.java

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/* w  ww . ja v a  2 s .  c o  m*/
        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;
}

From source file:com.z2data.files.WriteOperations.java

/**
 * Write error URL in file/* w  w w. j  av a 2 s. c  om*/
 * 
 * @param outputPath
 * @param URL
 * @param errorMessage
 */
public static void writeErrorData(String outputPath, String URL, String errorMessage) {
    File file = null;
    try {
        file = new File(outputPath);

        if (!file.exists()) {
            file.createNewFile();
        }

        String errorFileName = "ERRORS_URLS_" + file.getName();
        File errorFile = null;
        if (file.getParent() == null || file.getParent().isEmpty()) {
            errorFile = new File(errorFileName);
        } else {
            errorFile = new File(file.getParent() + errorFileName);
        }

        if (!errorFile.exists()) {
            errorFile.createNewFile();
        }
        FileUtils.writeStringToFile(errorFile, URL + "\t" + errorMessage, true);
        FileUtils.writeStringToFile(errorFile, System.lineSeparator(), true);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:com.kixeye.chassis.bootstrap.TestUtils.java

public static OutputStream createFile(String path) {
    try {/* w  ww .  java2s  . c  om*/
        Path p = Paths.get(SystemPropertyUtils.resolvePlaceholders(path));
        if (Files.exists(p)) {
            Files.delete(p);
        }
        File file = new File(path);
        if (!file.getParentFile().exists()) {
            if (!file.getParentFile().mkdirs()) {
                throw new RuntimeException("Unable to create parent file(s) " + file.getParent());
            }
        }
        return Files.newOutputStream(p);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:com.theelix.libreexplorer.FileManager.java

/**
 * Rename the given file//from   ww w  . j a v a  2 s  . c  o m
 *
 * @param sourceFile  The Target File
 * @param newFileName The New File Name
 * @throws IOException
 */
public static void rename(File sourceFile, String newFileName) throws IOException {
    sourceFile.renameTo(new File(sourceFile.getParent() + File.separator + newFileName));
}

From source file:com.beginner.core.utils.FileZip.java

/**
 * ,?-???,??,?//  w  w  w  .  j av a  2s. c  om
 * @param srcFile       ?
 * @param destParam    
 * @return             
 */
private static String buildDestinationZipFilePath(File srcFile, String destParam) {
    if (StringUtils.isEmpty(destParam)) {
        if (srcFile.isDirectory()) {
            destParam = srcFile.getParent() + File.separator + srcFile.getName() + ".zip";
        } else {
            String fileName = srcFile.getName().substring(0, srcFile.getName().lastIndexOf("."));
            destParam = srcFile.getParent() + File.separator + fileName + ".zip";
        }
    } else {
        createDestDirectoryIfNecessary(destParam); // ??
        if (destParam.endsWith(File.separator)) {
            String fileName = "";
            if (srcFile.isDirectory()) {
                fileName = srcFile.getName();
            } else {
                fileName = srcFile.getName().substring(0, srcFile.getName().lastIndexOf("."));
            }
            destParam += fileName + ".zip";
        }
    }
    return destParam;
}