Example usage for java.io File isFile

List of usage examples for java.io File isFile

Introduction

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

Prototype

public boolean isFile() 

Source Link

Document

Tests whether the file denoted by this abstract pathname is a normal file.

Usage

From source file:eu.liveandgov.ar.utilities.OS_Utils.java

/**
 *  Find the file in folder that its name contains initials 
 *    //from w w  w.j  a  v  a 2 s  .  co  m
 * @param initials
 * @param folder
 * @return
 */
public static String findfileAndroid(String initials, String folder) {

    String res = "";

    File yourDir = new File(folder);

    String name = "";
    for (File f : yourDir.listFiles()) {
        if (f.isFile())
            name = f.getName();
        if (name.contains(initials))
            res = name;
    }

    return res;
}

From source file:com.kegare.friendlymobs.util.Version.java

private static void initialize() {
    CURRENT = Optional.of(Strings.nullToEmpty(FriendlyMobs.metadata.version));
    LATEST = Optional.fromNullable(CURRENT.orNull());

    File file = FriendlyUtils.getModContainer().getSource();

    if (file != null && file.exists()) {
        if (file.isFile()) {
            if (StringUtils.endsWithIgnoreCase(FilenameUtils.getBaseName(file.getName()), "dev")) {
                DEV_DEBUG = true;/*  www. j  a v  a 2  s .com*/
            }
        } else {
            DEV_DEBUG = true;
        }
    } else if (!FMLForgePlugin.RUNTIME_DEOBF) {
        DEV_DEBUG = true;
    }

    if (StringUtils.endsWithIgnoreCase(getCurrent(), "dev")) {
        DEV_DEBUG = true;
    } else if (DEV_DEBUG) {
        FriendlyMobs.metadata.version += "-dev";
    }
}

From source file:aurelienribon.utils.io.FilenameHelper.java

/**
 * Gets the relative path from one file to another.
 *///from  w  w  w . j a  v  a  2  s .  c om
public static String getRelativePath(String targetPath, String basePath) {
    if (basePath == null || basePath.equals(""))
        return targetPath;
    if (targetPath == null || targetPath.equals(""))
        return "";

    String pathSeparator = File.separator;

    // Normalize the paths
    String normalizedTargetPath = FilenameUtils.normalizeNoEndSeparator(targetPath);
    String normalizedBasePath = FilenameUtils.normalizeNoEndSeparator(basePath);

    if (basePath.equals(targetPath))
        return "";

    // Undo the changes to the separators made by normalization
    if (pathSeparator.equals("/")) {
        normalizedTargetPath = FilenameUtils.separatorsToUnix(normalizedTargetPath);
        normalizedBasePath = FilenameUtils.separatorsToUnix(normalizedBasePath);

    } else if (pathSeparator.equals("\\")) {
        normalizedTargetPath = FilenameUtils.separatorsToWindows(normalizedTargetPath);
        normalizedBasePath = FilenameUtils.separatorsToWindows(normalizedBasePath);

    } else {
        throw new IllegalArgumentException("Unrecognised dir separator '" + pathSeparator + "'");
    }

    String[] base = normalizedBasePath.split(Pattern.quote(pathSeparator));
    String[] target = normalizedTargetPath.split(Pattern.quote(pathSeparator));

    // First get all the common elements. Store them as a string,
    // and also count how many of them there are.
    StringBuilder common = new StringBuilder();

    int commonIndex = 0;
    while (commonIndex < target.length && commonIndex < base.length
            && target[commonIndex].equals(base[commonIndex])) {
        common.append(target[commonIndex]).append(pathSeparator);
        commonIndex++;
    }

    if (commonIndex == 0) {
        return targetPath;
    }

    // The number of directories we have to backtrack depends on whether the base is a file or a dir
    // For example, the relative path from
    //
    // /foo/bar/baz/gg/ff to /foo/bar/baz
    //
    // ".." if ff is a file
    // "../.." if ff is a directory
    //
    // The following is a heuristic to figure out if the base refers to a file or dir. It's not perfect, because
    // the resource referred to by this path may not actually exist, but it's the best I can do
    boolean baseIsFile = true;

    File baseResource = new File(normalizedBasePath);

    if (baseResource.exists()) {
        baseIsFile = baseResource.isFile();

    } else if (basePath.endsWith(pathSeparator)) {
        baseIsFile = false;
    }

    StringBuilder relative = new StringBuilder();

    if (base.length != commonIndex) {
        int numDirsUp = baseIsFile ? base.length - commonIndex - 1 : base.length - commonIndex;

        for (int i = 0; i < numDirsUp; i++) {
            relative.append("..").append(pathSeparator);
        }
    }
    relative.append(normalizedTargetPath.substring(common.length()));
    return relative.toString();
}

From source file:com.glaf.shiro.SecurityConfig.java

public static void reload() {
    InputStream inputStream = null;
    try {/*w  w  w .  j  av a  2 s  .  co  m*/
        loading.set(true);
        String config_path = SystemProperties.getConfigRootPath() + "/conf/security/";
        String defaultFileName = config_path + "system-security.properties";
        File defaultFile = new File(defaultFileName);
        if (defaultFile.isFile()) {
            inputStream = new FileInputStream(defaultFile);
            LinkedHashMap<String, String> p = PropertiesUtils.load(inputStream);
            if (p != null) {
                Iterator<String> it = p.keySet().iterator();
                while (it.hasNext()) {
                    String key = it.next();
                    String value = p.get(key);
                    /**
                     * ?????????
                     */
                    if (!filterChainDefinitionMap.containsKey(key)) {
                        filterChainDefinitionMap.put(key, value);
                    }
                }
            }
            IOUtils.closeQuietly(inputStream);
            inputStream = null;
        }
        File directory = new File(config_path);
        if (directory.isDirectory()) {
            String[] filelist = directory.list();
            for (int i = 0; i < filelist.length; i++) {
                String filename = config_path + filelist[i];
                if (StringUtils.equals(filename, "system-security.properties")) {
                    continue;
                }
                File file = new File(filename);
                if (file.isFile() && file.getName().endsWith(".properties")) {
                    inputStream = new FileInputStream(file);
                    LinkedHashMap<String, String> p = PropertiesUtils.load(inputStream);
                    if (p != null) {
                        Iterator<String> it = p.keySet().iterator();
                        while (it.hasNext()) {
                            String key = it.next();
                            String value = p.get(key);
                            /**
                             * ?????????
                             */
                            if (!filterChainDefinitionMap.containsKey(key)) {
                                filterChainDefinitionMap.put(key, value);
                            }
                        }
                    }
                    IOUtils.closeQuietly(inputStream);
                    inputStream = null;
                }
            }
        }
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    } finally {
        loading.set(false);
        IOUtils.closeQuietly(inputStream);
    }
}

From source file:com.ibm.watson.developer_cloud.retrieve_and_rank.v1.util.ZipUtils.java

private static void addFilesToZip(final File currentParentDir, final ZipOutputStream out,
        final File globalParentDir) throws IOException {
    for (final File child : currentParentDir.listFiles()) {
        if (child.isDirectory()) {
            addFilesToZip(child, out, globalParentDir);
        } else if (child.isFile()) {
            writeZipEntry(out, globalParentDir.toURI().relativize(child.toURI()).toString(), readBytes(child));
        }//  www.  j  a  v  a  2  s  .  co  m
    }
}

From source file:com.kegare.caveworld.util.Version.java

private static void initialize() {
    CURRENT = Optional.of(Strings.nullToEmpty(Caveworld.metadata.version));
    LATEST = Optional.fromNullable(CURRENT.orNull());

    ModContainer mod = CaveUtils.getModContainer();
    File file = mod == null ? null : mod.getSource();

    if (file != null && file.exists()) {
        if (file.isFile()) {
            String name = FilenameUtils.getBaseName(file.getName());

            if (StringUtils.endsWithIgnoreCase(name, "dev")) {
                DEV_DEBUG = true;//  w  ww.j  a v  a 2s  . co m
            }
        } else if (file.isDirectory()) {
            DEV_DEBUG = true;
        }
    } else if (!FMLForgePlugin.RUNTIME_DEOBF) {
        DEV_DEBUG = true;
    }

    if (Caveworld.metadata.version.endsWith("dev")) {
        DEV_DEBUG = true;
    } else if (DEV_DEBUG) {
        Caveworld.metadata.version += "-dev";
    }
}

From source file:com.aspose.email.examples.outlook.pst.SplitAndMergePSTFile.java

public static void mergeMultiplePSTsIntoASinglePST() {

    // Path to files that will be merged into "source.pst".
    String mergeWithFolderPath = dataDir + "MergeWith";

    String mergeIntoFolderPath = dataDir + "MergeInto" + File.separator;

    // This will ensure that we can run this example as many times as we want. 
    // It will discard changes made to to the Source file in last run of this example.
    deleteAndRecopySampleFiles(mergeIntoFolderPath, dataDir + "MergeMultiplePSTsIntoASinglePST/");

    final PersonalStorage pst = PersonalStorage.fromFile(mergeIntoFolderPath + "source.pst");
    try {//from w w  w .ja  v  a2  s . c  o m
        pst.StorageProcessed.add(new StorageProcessedEventHandler() {
            public void invoke(Object sender, StorageProcessedEventArgs e) {
                pstMerge_OnStorageProcessed(sender, e);
            }
        });
        pst.ItemMoved.add(new ItemMovedEventHandler() {
            public void invoke(Object sender, ItemMovedEventArgs e) {
                pstMerge_OnItemMoved(sender, e);
            }
        });
        //Get a collection of all files in the directory
        ArrayList<String> results = new ArrayList<String>();

        File[] files = new File(mergeWithFolderPath).listFiles();
        //If this path name does not denote a directory, then listFiles() returns null.
        if (files == null)
            return;

        for (File file : files) {
            if (file.isFile() && file.getName().endsWith(".pst")) {
                results.add(file.getAbsolutePath());
            }
        }

        String[] fileNames = results.toArray(new String[0]);
        pst.mergeWith(fileNames);
    } finally {
        if (pst != null)
            (pst).dispose();
    }
}

From source file:com.denimgroup.threadfix.importer.cli.CommandLineMigration.java

private static void deleteFile(String oldFilePath) throws IOException {

    File fouput = new File(oldFilePath);
    if (fouput.exists() && fouput.isFile())
        if (fouput.delete())
            LOGGER.info("File " + oldFilePath + " has been deleted");
        else/*from   w  ww. j av a2 s .  co m*/
            LOGGER.info("File " + oldFilePath + " has not been deleted");
}

From source file:com.kegare.frozenland.util.Version.java

private static void initialize() {
    CURRENT = Optional.of(Strings.nullToEmpty(Frozenland.metadata.version));
    LATEST = Optional.fromNullable(CURRENT.orNull());

    File file = FrozenUtils.getModContainer().getSource();

    if (file != null && file.exists()) {
        if (file.isFile()) {
            String name = FilenameUtils.getBaseName(file.getName());

            if (StringUtils.endsWithIgnoreCase(name, "dev")) {
                DEV_DEBUG = true;// w  w w .  j  av  a 2 s.  c  o m
            }
        } else if (file.isDirectory()) {
            DEV_DEBUG = true;
        }
    } else if (!FMLForgePlugin.RUNTIME_DEOBF) {
        DEV_DEBUG = true;
    }

    if (Frozenland.metadata.version.endsWith("dev")) {
        DEV_DEBUG = true;
    } else if (DEV_DEBUG) {
        Frozenland.metadata.version += "-dev";
    }
}