Example usage for java.io File getName

List of usage examples for java.io File getName

Introduction

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

Prototype

public String getName() 

Source Link

Document

Returns the name of the file or directory denoted by this abstract pathname.

Usage

From source file:com.taunova.app.libview.components.ImageHelpers.java

public static File addPrefixToFile(File file, String prefix) {
    String name = FilenameUtils.getBaseName(file.getName());
    String extension = FilenameUtils.getExtension(file.getName());

    StringBuilder builder = new StringBuilder(file.getParent());
    builder.append(File.separator);
    builder.append(name);/* w  w w  .j  a  v  a2  s  .co  m*/
    builder.append(prefix);
    builder.append('.');
    builder.append(extension);
    return new File(builder.toString());
}

From source file:eu.hydrologis.jgrass.featureeditor.utils.Utilities.java

/**
 * Extracts the form file from a resource file (ex shapefile).
 * //from  w w  w .  j  a  v a  2s  .c  om
 * @param resourceFile the resource that has a form sidecar file.
 * @return the form file or null, if it doesn't exist.
 */
public static File getFormFile(File resourceFile) {

    String baseName = FilenameUtils.getBaseName(resourceFile.getName());
    File formFile = new File(resourceFile.getParentFile(), baseName + FORM);

    if (formFile.exists()) {
        return formFile;
    } else {
        return null;
    }
}

From source file:javacommon.excel.ReaderFactory.java

/**
 * ?Excel??//from   ww w.ja  v a 2  s.  c o  m
 * @see ExcelConstants
 * @param type Excel2003??xlx,2007??xlsx
 * @param file excel
 * @return Excel??
 * @throws IOException
 */
public static Reader getReader(File file) throws IOException {
    return new ExcelReader(
            getWorkBook(ExcelUtils.getVersionByFileName(file.getName()), FileUtils.openInputStream(file)));
}

From source file:net.dv8tion.jda.utils.AvatarUtil.java

public static Avatar getAvatar(File avatarFile) throws UnsupportedEncodingException {
    String[] split = avatarFile.getName().split("\\.");
    String type = split[split.length - 1];
    if (type.equalsIgnoreCase("jpg") || type.equalsIgnoreCase("jpeg") || type.equalsIgnoreCase("png")) {
        try {/*from w  w  w . j a v  a  2 s  .  c  o m*/
            //reading
            BufferedImage img = ImageIO.read(avatarFile);
            return getAvatar(img);
        } catch (IOException e) {
            JDAImpl.LOG.log(e);
        }
    } else {
        throw new UnsupportedEncodingException("Image type " + type + " is not supported!");
    }
    return null;
}

From source file:Main.java

/**
 * Creates a FileFilter for a specified description
 * and an array of allowed extensions. <br />
 * //ww w .  ja v a2s  . c  o  m
 * @param extensions the allowed extensions without a dot
 * @param description the displayed description
 * @return the created FileFilter
 */
public static FileFilter createFilter(final String[] extensions, final String description) {
    return new FileFilter() {

        @Override
        public boolean accept(File file) {
            if (file.isDirectory()) {
                return true;
            }
            String name = file.getName().toLowerCase();
            for (String e : extensions) {
                if (name.endsWith("." + e.toLowerCase())) {
                    return true;
                }
            }
            return false;
        }

        @Override
        public String getDescription() {
            return description;
        }
    };
}

From source file:com.knewton.mapreduce.io.sstable.BackwardsCompatibleDescriptor.java

/**
 * Implementation of {@link Descriptor#fromFilename(String)} that is backwards compatible with
 * older sstables//  w ww. j  a va2 s .  c  om
 *
 * @param filename
 * @return A descriptor for the sstable
 */
public static Descriptor fromFilename(String filename) {
    File file = new File(filename);
    return fromFilename(file.getParentFile(), file.getName()).left;
}

From source file:Main.java

public static void insertImage2MediaStore(Context context, String path) {
    File f = new File(path);
    if (f != null && f.exists()) {
        ContentValues values = new ContentValues();
        values.put(Media.DISPLAY_NAME, f.getName());
        values.put(Media.DESCRIPTION, f.getName());
        values.put(Media.MIME_TYPE, "image/jpeg");
        values.put(Media.DATA, path);

        Uri uri = context.getContentResolver().insert(Media.EXTERNAL_CONTENT_URI, values);
    }//w ww  .  j a va2  s  . c o m
}

From source file:DuplicatedMusicCleaner.java

public static void cleanupFolder(File folder) throws IOException {
    // System.out.println("Evaluate " + folder.getAbsolutePath());
    String[] fileNames = folder.list();
    Map<String, String> fileNamesWithoutExtension = new HashMap<String, String>();
    for (String fileName : fileNames) {
        File file = new File(folder, fileName);
        String nameWithoutExtension = StringUtils.substringBeforeLast(file.getName(), ".");
        fileNamesWithoutExtension.put(nameWithoutExtension, file.getAbsolutePath());
    }/*from   www .  j  a  v  a2  s .c  o  m*/

    for (String fileName : fileNames) {
        // System.out.println("Evaluate " + fileName);
        File file = new File(folder, fileName);
        if (file.isDirectory()) {
            cleanupFolder(file);
        } else {

            String nameWithoutExtension = StringUtils.substringBeforeLast(file.getName(), ".");
            String suffix = " 1";
            if (nameWithoutExtension.endsWith(suffix)) {
                String nameWithoutSuffix = StringUtils.substringBeforeLast(nameWithoutExtension, suffix);
                if (fileNamesWithoutExtension.keySet().contains(nameWithoutSuffix)) {
                    File originalFile = new File(fileNamesWithoutExtension.get(nameWithoutSuffix));
                    long originalFileLength = originalFile.length();
                    long fileLength = file.length();
                    if (originalFileLength == fileLength) {
                        System.err.println("Delete " + file.getName());
                        FileUtils.deleteQuietly(file);
                        // FileUtils.moveFile(file, new
                        // File(file.getAbsoluteFile() + ".todelete"));
                    }
                }
            }
            /*
             * if(file.getName().endsWith(".todelete")) { String newFileName
             * = StringUtils.substringBeforeLast(file.getName(),
             * ".todelete"); File parent = file.getParentFile(); File
             * parentParent = parent.getParentFile(); newFileName =
             * parentParent.getName() + "_" + parent.getName() + "_" +
             * newFileName;
             * 
             * File target = new File("/Users/cyrilleleclerc/todelete",
             * newFileName); System.out.println(target);
             * FileUtils.moveFile(file, target);
             * 
             * }
             */
        }
    }

}

From source file:com.compomics.pladipus.controller.setup.InstallActiveMQ.java

private static File findFile(File root, String fileName) {
    File configFile = null;//from  w ww  .  j  av  a2s  .c  o  m
    File[] list = root.listFiles();
    for (File f : list) {
        if (f.getName().equals(fileName)) {
            configFile = f;
        } else if (f.isDirectory()) {
            configFile = findFile(f, fileName);
        }
        if (configFile != null) {
            break;
        }
    }
    return configFile;
}

From source file:com.stratio.mojo.scala.crossbuild.ITs.java

public static boolean verify(final List<String> scalaBinaryVersions, final List<String> artifactNames,
        final List<String> targetPaths, final List<String> testCases)
        throws IOException, FileNotFoundException {
    if (artifactNames.size() != targetPaths.size()) {
        throw new IllegalArgumentException("artifactNames and modulePaths must be equal size");
    }/*from   ww w  . ja va2  s.  c o m*/
    if (scalaBinaryVersions.isEmpty()) {
        throw new IllegalArgumentException("At least one scalaBinaryVersion must be provided");
    }
    for (final String scalaBinaryVersion : scalaBinaryVersions) {
        for (int i = 0; i < artifactNames.size(); i++) {
            final String artifactName = artifactNames.get(i);
            final String artifactId = artifactName + "_" + scalaBinaryVersion;
            final File targetPath = new File(targetPaths.get(i));
            final File targetScalaPath = new File(targetPath, scalaBinaryVersion);
            final File artifactPath = new File(targetScalaPath, artifactId + "-1.jar");
            if (!artifactPath.isFile()) {
                throw new FileNotFoundException("Could not find generated artifact: " + artifactPath);
            }
            if (testCases.isEmpty()) {
                continue;
            }
            final File surefireReportsPath = new File(targetScalaPath, "surefire-reports");
            if (!surefireReportsPath.isDirectory()) {
                throw new FileNotFoundException(
                        "Could not find surefire-reports directory: " + surefireReportsPath);
            }
            final File[] testReports = surefireReportsPath.listFiles(new FileFilter() {
                @Override
                public boolean accept(final File pathname) {
                    return pathname.getName().endsWith(".xml") && pathname.getName().startsWith("TEST-");
                }
            });
            if (testReports.length == 0) {
                throw new FileNotFoundException("Could not find test reports");
            }
            for (final String testCase : testCases) {
                final String scalaString = "[Scala " + scalaBinaryVersion + "]";
                boolean found = false;
                for (final File testReport : testReports) {
                    final String testReportString = IOUtils.toString(new FileInputStream(testReport));
                    final String testCaseWithSuffix = testCase + " " + scalaString;
                    if (testReportString.contains(testCaseWithSuffix)) {
                        found = true;
                        break;
                    }
                }
                if (!found) {
                    throw new RuntimeException("JUnit XML test report does not contain Scala version string ("
                            + scalaString + ")");
                }
            }
        }
    }
    return true;
}