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.qait.automation.samjbehavedemo.utils.FileHandler.java

public static List<String> getFileNames(String filedirpath, final String filenameendswith) {

    List<String> filenames = new ArrayList<>();

    File[] files = getFile(filedirpath).listFiles();

    for (File file : files) {
        String filename = file.getName();
        if (file.isFile() && filename.toLowerCase().endsWith(filenameendswith.toLowerCase())) {
            filenames.add(filename);/* ww  w. jav  a 2s.  c o  m*/
        }
    }

    if (filenames.isEmpty()) {
        throw new NullPointerException(
                "There are no files matching the criteria in directoy: " + filedirpath.toUpperCase());
    }

    return filenames;
}

From source file:ijfx.ui.utils.NamingUtils.java

public static File replaceWithExtension(File originalFile, String extension) {
    String basename = FilenameUtils.getBaseName(originalFile.getName());
    if (extension.startsWith(".") == false)
        extension = "." + extension;
    return new File(originalFile.getParentFile(), basename + extension);
}

From source file:Main.java

/**
 * return a file handle for a manifest file derived from the shared file name
 * //from   w w  w .jav a2 s  .co m
 * @param path the path to the shared file
 * @return a file handle to the manifest file
 */
public static File getManifestPath(String path) {
    File mManifestPath = new File(path);
    File mManifestFile = new File(mManifestPath.getParent(), ".manifest-" + mManifestPath.getName());
    return mManifestFile;
}

From source file:com.github.geequery.codegen.util.GenUtil.java

public static boolean isModified(File java) throws IOException {
    if (!java.getName().endsWith(".java")) {
        throw new IllegalArgumentException();
    }//  www . j a va  2 s .com
    final Holder<Integer> result = new Holder<Integer>(-1);
    IOUtils.processFile(java, new TextFileCallback() {
        @Override
        public File getTarget(File source) {
            return null;
        }

        @Override
        public String processLine(String line) {
            if (line.trim().equals("@NotModified")) {
                result.set(0);
            } else if (line.trim().startsWith("public class ")) {
                result.set(1);
            }
            return null;
        }

        @Override
        protected boolean breakProcess() {
            return result.get() != -1;
        }
    });
    return result.get() != 0;
}

From source file:info.magnolia.importexport.BootstrapFilesComparator.java

private static String getExtension(File file) {
    String ext = StringUtils.substringAfterLast(file.getName(), ".");
    if (("." + ext).equals(DataTransporter.GZ) || ("." + ext).equals(DataTransporter.ZIP)) {
        ext = StringUtils.substringAfterLast(StringUtils.substringBeforeLast(file.getName(), "."), ".");
    }//from ww  w . j  a va2  s  . com
    return ext;
}

From source file:FolderZiper.java

static private void addFolderToZip(String path, String srcFolder, ZipOutputStream zip) throws Exception {
    File folder = new File(srcFolder);

    for (String fileName : folder.list()) {
        if (path.equals("")) {
            addFileToZip(folder.getName(), srcFolder + "/" + fileName, zip);
        } else {/*w w  w . j  av  a  2  s.com*/
            addFileToZip(path + "/" + folder.getName(), srcFolder + "/" + fileName, zip);
        }
    }
}

From source file:Main.java

public static void valiFileIsExists(File file) throws FileNotFoundException {
    if (!file.exists()) {
        throw new FileNotFoundException("File '" + file.getName() + "' not found!");
    }/*from  w  ww. j  a v  a  2 s .co m*/
}

From source file:Main.java

/**
 * Takes a full file path string and returns a valid XML Name equivalent
 * via the {@link #toValidXMLName(String)} method.
 * @param fullFilePath as a String//ww w  .  j  a  v a 2s  . c o  m
 * @return A valid XML name conversion of that file name.
 */
public static String fileNameToURI(String fullFilePath) {
    if (fullFilePath == null || fullFilePath.trim().equals("")) {
        fullFilePath = "";
    }
    File theFile = new File(fullFilePath);
    return toValidXMLName(theFile.getName());
}

From source file:Main.java

private static boolean deleteFileWithExceptsInner(File file, String suffix, String[] exceptFileNames,
        AtomicBoolean excepted) {
    String fileName = file.getName().toLowerCase(Locale.US);
    if (canDeleteWithSuffixInner(fileName, suffix) && !equalsFileNamesInner(fileName, exceptFileNames)) {
        return file.delete();
    } else {//from   www .  j  a  va 2  s.  co m
        if (excepted != null)
            excepted.set(true);
    }
    return true;
}

From source file:com.taobao.datax.engine.schedule.JarLoader.java

private static URL[] getUrl(String path) {
    /* check path exist */
    if (null == path || StringUtils.isBlank(path)) {
        throw new IllegalArgumentException("Path cannot be empty .");
    }/*from  w w  w  .  ja  v  a  2 s. c  o  m*/

    File jarPath = new File(path);
    if (!jarPath.exists() || !jarPath.isDirectory()) {
        throw new IllegalArgumentException("Path must be directory .");
    }

    /* set filter */
    FileFilter jarFilter = new FileFilter() {
        @Override
        public boolean accept(File pathname) {
            return pathname.getName().endsWith(".jar");
        }
    };

    /* iterate all jar */
    File[] allJars = new File(path).listFiles(jarFilter);
    URL[] jarUrls = new URL[allJars.length];

    for (int i = 0; i < allJars.length; i++) {
        try {
            jarUrls[i] = allJars[i].toURI().toURL();
        } catch (MalformedURLException e) {
            logger.error(ExceptionTracker.trace(e));
            throw new DataExchangeException(e.getCause());
        }
        logger.debug(jarUrls[i]);
    }

    return jarUrls;
}