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:com.beginner.core.utils.Tools.java

/**
 * ?txt?//from  ww w.j a v a 2 s  .  co  m
 * @param filepath    
 * @return String    
 * @since 1.0.0
 */
public static String readTxtFile(String path) {
    try {
        String filePath = String.valueOf(Thread.currentThread().getContextClassLoader().getResource(""))
                + "../../"; //
        filePath = filePath.replaceAll("file:/", "");
        filePath = filePath.replaceAll("%20", " ");
        filePath = filePath.trim() + path.trim();
        if (filePath.indexOf(":") != 1) {
            filePath = File.separator + filePath;
        }
        String encoding = "utf-8";
        File file = new File(filePath);
        if (file.isFile() && file.exists()) { // ?
            InputStreamReader read = new InputStreamReader(new FileInputStream(file), encoding); // ??
            BufferedReader bufferedReader = new BufferedReader(read);
            String lineTxt = null;
            while ((lineTxt = bufferedReader.readLine()) != null) {
                return lineTxt;
            }
            read.close();
        } else {
            System.out.println("?,?:" + filePath);
        }
    } catch (Exception e) {
        System.out.println("?");
    }
    return "";
}

From source file:fll.web.GatherBugReport.java

/**
 * Add the web application and tomcat logs to the zipfile.
 *//*  w  w  w.  j  ava2s . c  o  m*/
private static void addLogFiles(final ZipOutputStream zipOut, final ServletContext application)
        throws IOException {

    // get logs from the webapp
    final File fllAppDir = new File(application.getRealPath("/"));
    final File[] webLogs = fllAppDir.listFiles(new FilenameFilter() {
        @Override
        public boolean accept(final File dir, final String name) {
            return name.startsWith("fllweb.log");
        }
    });
    if (null != webLogs) {
        for (final File f : webLogs) {
            if (f.isFile()) {
                FileInputStream fis = null;
                try {
                    zipOut.putNextEntry(new ZipEntry(f.getName()));
                    fis = new FileInputStream(f);
                    IOUtils.copy(fis, zipOut);
                    fis.close();
                } finally {
                    IOUtils.closeQuietly(fis);
                }
            }
        }
    }

    // get tomcat logs
    final File webappsDir = fllAppDir.getParentFile();
    LOGGER.trace("Webapps dir: " + webappsDir.getAbsolutePath());
    final File tomcatDir = webappsDir.getParentFile();
    LOGGER.trace("Tomcat dir: " + tomcatDir.getAbsolutePath());
    final File tomcatLogDir = new File(tomcatDir, "logs");
    LOGGER.trace("tomcat log dir: " + tomcatLogDir.getAbsolutePath());
    final File[] tomcatLogs = tomcatLogDir.listFiles();
    if (null != tomcatLogs) {
        for (final File f : tomcatLogs) {
            if (f.isFile()) {
                FileInputStream fis = null;
                try {
                    zipOut.putNextEntry(new ZipEntry(f.getName()));
                    fis = new FileInputStream(f);
                    IOUtils.copy(fis, zipOut);
                    fis.close();
                } finally {
                    IOUtils.closeQuietly(fis);
                }
            }
        }
    }

}

From source file:io.proleap.cobol.TestGenerator.java

protected static boolean isCobolFile(final File inputFile) {
    final String extension = FilenameUtils.getExtension(inputFile.getName()).toLowerCase();
    return inputFile.isFile() && Arrays.asList(COBOL_FILE_EXTENSIONS).contains(extension);
}

From source file:io.proleap.vb6.TestGenerator.java

public static void generateTestClasses(final File inputDirectory, final File outputDirectory,
        final String packageName) throws IOException {
    final String outputDirectoryPath = outputDirectory.getPath();

    if (inputDirectory.isDirectory()) {
        // for each of the files in the directory
        for (final File inputDirectoryFile : inputDirectory.listFiles()) {
            // if the file is a VB6 relevant file
            if (inputDirectoryFile.isFile() && !inputDirectoryFile.isHidden()
                    && (isClazzModule(inputDirectoryFile) || isStandardModule(inputDirectoryFile))) {
                generateTestClass(inputDirectoryFile, outputDirectory, packageName);
                generateTreeFile(inputDirectoryFile, inputDirectory);
            }//from   w  ww .ja v a  2 s  .  co m
            // else, if the file is a relevant directory
            else if (inputDirectoryFile.isDirectory() && !isDirectoryExcluded(inputDirectoryFile)) {
                final File subInputDirectory = inputDirectoryFile;
                final String subInputDirectoryName = subInputDirectory.getName();

                if (!".".equals(subInputDirectoryName) && !"..".equals(subInputDirectoryName)) {
                    /*
                     * determine the output directory, where test classes
                     * should be placed
                     */
                    final File subOutputDirectory = new File(outputDirectoryPath + "/" + subInputDirectoryName);
                    subOutputDirectory.mkdirs();

                    // determine the package name of test classes
                    final String subPackageName = Strings.isBlank(packageName) ? subInputDirectoryName
                            : packageName + "." + subInputDirectoryName;

                    generateTestClasses(subInputDirectory, subOutputDirectory, subPackageName);
                }
            }
        }
    }
}

From source file:de.tudarmstadt.ukp.lmf.hibernate.HibernateConnect.java

/**
 * Returns all files from the folder and its subfolders
 *
 * @deprecated this method is marked for deletion
 *///from ww  w.j a  v a2 s  .  c o m
@Deprecated
public static Set<File> getAllFiles(File folder) {
    Set<File> result = new HashSet<File>();
    if (folder.isFile() && folder.getName().endsWith(".hbm.xml")) {
        result.add(folder);
    } else if (folder.isDirectory()) {
        for (File f : folder.listFiles()) {
            result.addAll(getAllFiles(f));
        }
    }
    return result;
}

From source file:com.frostwire.gui.library.M3UPlaylist.java

/**
 * Call this when you want to save the contents of the playlist.
 * NOTE: only local files can be saved in M3U format, filters out URLs 
 * that are not part of the local filesystem
 * @exception IOException Throw when save failed.
 * @exception IOException Throw when save failed.
 */// www  .  java2s. c  om
public static void save(String fileName, List<File> files) throws IOException {
    File playListFile = new File(fileName);
    // if all songs are new, just get rid of the old file.  this may
    // happen if a delete was done....
    if (files.size() == 0) {
        //            if (playListFile.exists()) {
        //                playListFile.delete();
        //            }
        return;
    }

    PrintWriter m3uFile = null;
    try {
        m3uFile = new PrintWriter(new FileWriter(playListFile.getCanonicalPath(), false));

        m3uFile.write(M3U_HEADER);
        m3uFile.println();

        for (File currFile : files) {
            // only save files that are local to the file system
            if (currFile.isFile()) {
                File locFile;
                locFile = new File(currFile.toURI());

                // first line of song description...
                m3uFile.write(SONG_DELIM);
                m3uFile.write(SEC_DELIM);
                // try to write out seconds info....
                //if( currFile.getProperty(PlayListItem.LENGTH) != null )
                //    m3uFile.write("" + currFile.getProperty(PlayListItem.LENGTH) + ",");
                //else
                m3uFile.write("" + -1 + ",");
                m3uFile.write(currFile.getName());
                m3uFile.println();
                // canonical path follows...
                m3uFile.write(locFile.getCanonicalPath());
                m3uFile.println();
            }
        }
    } finally {
        IOUtils.closeQuietly(m3uFile);
    }
}

From source file:org.psikeds.common.config.ConfigDirectoryHelper.java

/**
 * Look for a configuration file within the configuration directory.
 * /* w w  w.  j  a  v a2s  .  c om*/
 * @param path
 *          name of the configuration file
 * @return File object if the config file exists and is readable;
 *         null otherwise
 */
static File resolveConfigFile(final String path) {
    File resolved = new File(resolveConfigDir(), path);
    LOGGER.debug("Configuration file resolved to {}", resolved.getAbsolutePath());
    if (!resolved.exists() || !resolved.isFile() || !resolved.canRead()) {
        LOGGER.warn("Configuration file {} does not exist or is not readable!", resolved.getAbsolutePath());
        resolved = null;
    }
    return resolved;
}

From source file:edu.usc.polar.CoreNLP.java

public static void dir(String path, String[] args) {
    try {//from w ww .  ja v  a  2 s.  c om

        File root = new File(path);
        if (root.isFile()) {

            if (counter >= 1000 || file == null) {
                counter = 0;
                jsonCount++;
                file = new File("C:\\Users\\Snehal\\Documents\\tikaSimilarityTestSet\\CoreNLP\\NER_" + jsonCount
                        + ".json");
                if (jsonFile != null) {
                    jsonFile.write("{\"NER_CoreNLP\":");
                    jsonFile.write(jsonArray.toJSONString());
                    jsonFile.write("}");
                    //System.out.println(jsonArray.toJSONString());
                    jsonFile.close();
                }
                jsonFile = new FileWriter(file);
                jsonArray = new JSONArray();
            }

            if (!root.getName().equals((".DS_Store"))) {
                StanfordCoreNLP(root.getAbsolutePath(), args);
                counter++;
            }
        } else {
            File[] list = root.listFiles();
            if (list == null) {
                return;
            }
            for (File f : list) {
                if (f.isDirectory()) {
                    dir(f.getAbsolutePath(), args);
                    // System.out.println( "Dir:" + f.getAbsoluteFile() );
                } else {
                    if (counter >= 1000 || file == null) {
                        counter = 0;
                        jsonCount++;
                        file = new File("C:\\Users\\Snehal\\Documents\\tikaSimilarityTestSet\\CoreNLP\\NER_"
                                + jsonCount + ".json");
                        // System.out.print("check"+jsonArray.toJSONString());
                        if (jsonFile != null) {
                            jsonFile.write("{\"NER_CoreNLP\":");
                            jsonFile.write(jsonArray.toJSONString());
                            jsonFile.write("}");
                            //System.out.println(jsonArray.toJSONString());
                            jsonFile.close();
                        }
                        jsonFile = new FileWriter(file);
                        jsonArray = new JSONArray();
                    }

                    if (!f.getName().equals((".DS_Store"))) {
                        StanfordCoreNLP(f.getAbsolutePath(), args);
                        counter++;
                        // add json   
                    }
                }
            }
        }
    } catch (Exception e) {
        e.toString();

    }
}

From source file:FileUtil.java

/**
 * Gets file date and time.//  w ww .  j a v a  2s.c  o m
 *
 * @param url The URL of the file for which date and time will be returned.
 * @return Returns long value which is the date and time of the file. If any error
 *         occures returns -1 (=no file date and time available).
 */
public static long getFileDateTime(URL url) {
    if (url == null) {
        return -1;
    }

    String fileName = url.getFile();
    if (fileName.charAt(0) == '/' || fileName.charAt(0) == '\\') {
        fileName = fileName.substring(1, fileName.length());
    }

    try {
        File file = new File(fileName);
        // File name must be a file or a directory.
        if (!file.isDirectory() && !file.isFile()) {
            return -1;
        }

        return file.lastModified();
    } catch (java.lang.Exception e) { // Trap all Exception based exceptions and return -1.
        return -1;
    }
}

From source file:com.itmanwuiso.checksums.FileDuplicateChecker.java

private static void createTaske(File file) {
    try {/*ww  w .  j a va 2 s  .c o  m*/
        if (file.isFile()) {
            HashTask task = new HashTask(file, hashers, storage);
            FileDuplicateChecker.increment();
            checksumPool.execute(task);
        }
    } catch (Exception e) {
        logger.error(file.toString(), e);
    }
}