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.splunk.shuttl.archiver.util.UtilsBucket.java

private static File getTheCsvFileFromBucket(Bucket csvBucket) {
    for (File file : csvBucket.getDirectory().listFiles())
        if (FilenameUtils.getExtension(file.getName()).equals("csv"))
            return file;
    throw new NoCsvFileFoundException();
}

From source file:muffinc.yafdivj.helper.FeretHandler.java

public static void move(File file) {
    try {//  w ww. j  a  va2s .c  o  m

        String newFolder = NEW_FOLDER + file.getName().substring(1, 5) + "/";
        File file1 = new File(newFolder);

        if (!file1.exists()) {
            file1.mkdirs();
        }

        Files.copy(file.toPath(), new File(newFolder + file.getName()).toPath());

    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:Main.java

private static void searchDir(File dirFile) {
    File[] files = dirFile.listFiles();
    if (files != null) {
        for (File file : files) {
            if (file.isDirectory()) {
                if (file.getName().subSequence(0, 1).equals(".") || file.getName().equals("Android")
                        || file.getPath().equalsIgnoreCase("/storage/emulated")) {

                } else {
                    searchDir(file);/*w  w w. ja v a  2s  .c o m*/
                }
            } else {
                if (file.getName().toLowerCase().contains(fileType.toLowerCase())) {
                    listFile.add(file);
                }
            }
        }
    }
}

From source file:Main.java

/**
 * Copy configuration file from assets to data folder.
 *
 * @param file File to copy//w  w  w  . ja  v a2  s .co  m
 */
private static void copyAssetToData(File file) {
    try {
        InputStream myInput = mContext.getAssets().open(file.getName());
        String outFileName = file.getPath();
        OutputStream myOutput = new FileOutputStream(outFileName);
        byte[] buffer = new byte[1024];
        int length;
        while ((length = myInput.read(buffer)) > 0) {
            myOutput.write(buffer, 0, length);
        }
        myOutput.flush();
        myOutput.close();
        myInput.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Main.java

private static void addFiles(File root, Vector<String> files) {
    if (root == null)
        return;//from  ww  w  .  j av a2  s.  c  o m
    File[] listFiles = root.listFiles();
    if (listFiles == null)
        return;
    for (File f : listFiles) {

        if (f.isDirectory())
            addFiles(f, files);
        else if (f.getName().endsWith(".pfy"))
            files.add(f.getAbsolutePath());

    }

}

From source file:Main.java

/**
 * Get the list of xml files in the bookmark export folder.
 * @return The list of xml files in the bookmark export folder.
 *//*  w  w  w  .j  a  va2 s  .  c  om*/
public static List<String> getExportedBookmarksFileList() {
    List<String> result = new ArrayList<String>();

    File folder = Environment.getExternalStorageDirectory();

    if (folder != null) {

        FileFilter filter = new FileFilter() {

            @Override
            public boolean accept(File pathname) {
                if ((pathname.isFile()) && (pathname.getPath().toLowerCase(Locale.US).endsWith(".xml")
                        || pathname.getPath().toLowerCase(Locale.US).endsWith(".json"))) {
                    return true;
                }
                return false;
            }
        };

        File[] files = folder.listFiles(filter);

        for (File file : files) {
            result.add(file.getName());
        }
    }

    Collections.sort(result, new Comparator<String>() {

        @Override
        public int compare(String arg0, String arg1) {
            return arg1.compareTo(arg0);
        }
    });

    return result;
}

From source file:Main.java

public static void copyFileToDir(File from, File toDir, PrintStream reportStream) {
    final File to = new File(toDir, from.getName());
    copyFile(from, to, reportStream);// w  w  w .j av a 2s  .  c om
}

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

public static File addSuffix(File original, String suffix) {

    String baseName = FilenameUtils.getBaseName(original.getName());
    String extension = FilenameUtils.getExtension(original.getName());
    String finalName = new StringBuilder().append(baseName).append("_").append(suffix).append(".")
            .append(extension).toString();

    return new File(original.getParent(), finalName);
}

From source file:Main.java

public static void moveAll(final File fromFolder, final File toFolder, final boolean overwrite,
        final boolean clearDestinationFolder) {
    if (!fromFolder.exists())
        throw new RuntimeException("From folder " + fromFolder.getAbsolutePath() + " does not exist");
    if (!toFolder.exists())
        toFolder.mkdirs();//  ww w  .ja v  a 2s  . c  om
    else if (clearDestinationFolder)
        recursiveDelete(toFolder, true);
    for (File fromFile : fromFolder.listFiles()) {
        File toFile = new File(toFolder, fromFile.getName());
        if (!clearDestinationFolder && toFile.exists()) {
            if (overwrite)
                recursiveDelete(toFile);
            else
                continue;
        }
        if (!fromFile.renameTo(toFile))
            throw new RuntimeException(
                    "Cannot rename " + fromFile.getAbsolutePath() + " to " + toFile.getAbsolutePath());
    }
}

From source file:Main.java

private static Bitmap getThumbnail(String filePath, int targetW, int targetH) {
    Bitmap bitmap = null;/*ww w.  j ava2s  .  c  o m*/

    File file = new File(filePath);
    String fileName = file.getName();
    if (fileName.lastIndexOf(".") < 0) {
        return bitmap;
    }

    String fileExtension = fileName.substring(fileName.lastIndexOf(".") + 1);

    if (fileExtension.equalsIgnoreCase(IMAGE_TYPT_BMP) || fileExtension.equalsIgnoreCase(IMAGE_TYPT_JPG)
            || fileExtension.equalsIgnoreCase(IMAGE_TYPT_JPEG) || fileExtension.equalsIgnoreCase(IMAGE_TYPT_PNG)
            || fileExtension.equalsIgnoreCase(IMAGE_TYPT_GIF)) {

        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;
        BitmapFactory.decodeFile(filePath, options);
        int bitmapRealWidth = options.outWidth;
        int bitmapRealHeight = options.outHeight;
        options.outWidth = targetW;
        if (bitmapRealWidth > 0) {
            options.outHeight = bitmapRealHeight * targetW / bitmapRealWidth;
        }

        options.inJustDecodeBounds = false;

        if (targetW > 0) {
            options.inSampleSize = bitmapRealWidth / targetW;
        }

        options.inPurgeable = true;
        options.inInputShareable = true;
        options.inPreferredConfig = Config.ARGB_4444;

        bitmap = BitmapFactory.decodeFile(filePath, options);
    }

    return bitmap;
}