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:eu.europa.esig.dss.applet.util.FileTypeDetectorUtils.java

private static boolean isASiCE(final File file) {
    return file.getName().toLowerCase().endsWith(".asice");
}

From source file:Main.java

/**
 * Displays a {@link JFileChooser} to select a file.
 *
 * @param title The title of the dialog.
 * @param startDirectory The directory where the dialog is initialed opened.
 * @param fileExtension File extension to filter each content of the opened
 * directories. Example ".xml".//  w  w w  . j  av  a  2s  .  c om
 * @param startFile The preselected file where the dialog is initialed opened.
 * @return The {@link File} object selected, returns null if no file was selected.
 */
public static File chooseFile(String title, String startDirectory, final String fileExtension,
        String startFile) {
    JFileChooser chooser = new JFileChooser();
    chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    chooser.setDialogTitle(title);

    if (fileExtension != null && !fileExtension.trim().equals("")) {
        FileFilter filter = new FileFilter() {

            @Override
            public boolean accept(File pathname) {
                return pathname.isDirectory() || pathname.getName().endsWith(fileExtension);
            }

            @Override
            public String getDescription() {
                return "(" + fileExtension + ")";
            }
        };

        chooser.setFileFilter(filter);
    }

    if (startDirectory != null && !startDirectory.trim().equals("")) {
        chooser.setCurrentDirectory(new File(startDirectory));
    }

    if (startFile != null && !startFile.trim().equals("")) {
        chooser.setSelectedFile(new File(startFile));
    }

    int status = chooser.showOpenDialog(null);

    if (status == JFileChooser.APPROVE_OPTION) {
        return chooser.getSelectedFile();
    }

    return null;
}

From source file:Main.java

public static void copyDir(String src, String dst) {
    try {//w w  w  .j  a  v  a 2  s . c o  m
        File fileSrc = new File(src);
        if (!fileSrc.exists()) {
            return;
        }
        File[] filelist = fileSrc.listFiles();
        File fileDst = new File(dst);
        if (!fileDst.exists()) {
            fileDst.mkdirs();
        }
        for (File f : filelist) {
            if (f.isDirectory()) {
                copyDir(f.getPath() + "/", dst + f.getName() + "/");
            } else {
                copyFile(f.getPath(), dst + f.getName());
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:eu.databata.engine.util.PropagationUtils.java

public static String removeExtension(File file) {
    String s = file.getName();
    return s.substring(0, s.lastIndexOf('.'));
}

From source file:com.grapeshot.halfnes.FileUtils.java

public static String stripExtension(final File f) {
    String s = f.getName();
    if (s == null || s.equals("")) {
        return "";
    }// w ww. j  av  a 2s. c  om
    int split = s.lastIndexOf('.');
    if (split < 0) {
        return "";
    }
    return s.substring(0, split);
}

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.
 *///from  ww  w  .  ja va  2s . c om
public static List<String> getExportedBookmarksFileList() {
    List<String> result = new ArrayList<String>();

    File folder = getBookmarksExportFolder();

    if (folder != null) {

        FileFilter filter = new FileFilter() {

            @Override
            public boolean accept(File pathname) {
                if ((pathname.isFile()) && (pathname.getPath().endsWith(".xml"))) {
                    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 boolean copyAsset(Context context, AssetManager am, boolean force) {
    File newDir = getSDDir(context);
    File sd = Environment.getExternalStorageDirectory();
    if (sd != null && sd.exists() && sd.isDirectory() && newDir != null && newDir.exists()
            && newDir.isDirectory()) {
        File hpDir = new File(sd, ".hp48");
        if (hpDir.exists()) {
            File allFiles[] = hpDir.listFiles();
            if (allFiles != null && allFiles.length > 0) {
                Log.i("x48",
                        "Moving x48 files from the old dir " + sd.getAbsolutePath() + " to the proper one :");
                for (File file : allFiles) {
                    File newFile = new File(newDir, file.getName());
                    Log.i("x48", "Moving " + file.getAbsolutePath() + " to " + newFile);
                    file.renameTo(newFile);
                }// ww w.  jav  a2s  .  c  om
            }
            Log.i("x48", "Deleting old directory");
            hpDir.delete();
        }
    }
    return copyAsset(am, newDir, force);
}

From source file:com.alvermont.terraj.fracplanet.io.FileUtils.java

/**
 * Add an extension to the filename of a <code>File</code> object. If
 * an extension is already present then it is not modified.
 *
 * @param f The file to have its extension modified
 * @param newExt The new extension to be added e.g. ".pov"
 * @return A new file object with a possibly different file extension
 *///from  w w w .j  a  v a 2  s . c  om
public static File addExtension(File f, String newExt) {
    File file = f;

    String name = file.getName();

    final int pos = name.lastIndexOf(".");

    if (pos == -1) {
        name = name;

        if (!newExt.startsWith(".")) {
            name += ".";
        }

        name += newExt;

        file = new File(file.getParentFile(), name);
    }

    return file;
}

From source file:com.carteblanche.kwd.parsers.TestCaseParser.java

public static KWDTestCase parse(File csv, String cvsSplitBy) {

    BufferedReader br = null;/*from w w w.j  a  v  a  2  s. co m*/
    String line = "";
    String csvFile = csv.getAbsolutePath();

    try {

        File file = new File(csvFile);

        String testCaseName = file.getName();
        testCaseName = testCaseName.replace(".csv", "");
        testCaseName = StringUtils
                .capitalize(StringUtils.join(StringUtils.splitByCharacterTypeCamelCase(testCaseName), ' '));
        br = new BufferedReader(new FileReader(csvFile));
        ArrayList<KWDTestMethod> testMethods = new ArrayList<KWDTestMethod>();
        while ((line = br.readLine()) != null) {

            // use comma as separator
            String[] columns = line.split(cvsSplitBy);

            if (columns.length < 1) {
                System.out.println("Every row should have atleast 1 Column");
                System.exit(122);
            }

            ArrayList<String> parameters = new ArrayList<String>();
            for (int i = 1; i < columns.length; i++) {
                parameters.add(columns[i]);
            }
            KWDTestMethod testMethod = new KWDTestMethod(columns[0], parameters);
            testMethod.setClasssName("com.carteblanche.kwd.tests.Login");
            testMethods.add(testMethod);
        }
        KWDTestCase testCase = new KWDTestCase(testCaseName, testMethods);
        return testCase;
        // return new KWDTestSuite(testSuiteName, testcases);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (br != null) {
            try {
                br.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    return null;
}

From source file:com.grapeshot.halfnes.FileUtils.java

public static String getExtension(final File f) {
    return getExtension(f.getName());
}