List of usage examples for java.io File getName
public String getName()
From source file:Main.java
public static int getCPUCores() { //Strategy 1. //The value may less than real value. //int cores_runtime = Runtime.getRuntime().availableProcessors(); //Strategy 2. int cores = 1; class CpuFilter implements FileFilter { @Override/* w w w .j a v a2s. co m*/ public boolean accept(File pathname) { return Pattern.matches("cpu[0-9]", pathname.getName()); } } try { File dir = new File("/sys/devices/system/cpu/"); File[] files = dir.listFiles(new CpuFilter()); cores = files.length; } catch (Exception e) { e.printStackTrace(); } return cores; }
From source file:Main.java
public static String getFileExtenSion(File file) { String ex;/*from w ww .j ava2 s .co m*/ String filename; try { filename = file.getName(); ex = filename.substring(filename.lastIndexOf(".") + 1); } catch (Exception e) { return ""; } return ex.toLowerCase(Locale.getDefault()); }
From source file:Main.java
public static boolean isNoMediaDir(File dir) { boolean result = false; if (dir == null || dir.isFile()) { result = true;//from w w w . j a va 2 s . c o m } else { File[] files = dir.listFiles(); if (files != null) { for (File childFile : files) { if (childFile.isFile() && ".nomedia".equals(childFile.getName())) { result = true; break; } } } } return result; }
From source file:andrew.addons.NextFile.java
public static String findExt(String folder, String file) { File dir = new File(folder); File[] list = dir.listFiles(); if (list != null) { for (File fil : list) { if (file.equals(FilenameUtils.removeExtension(fil.getName()))) return fil.getName(); }/*from w w w .jav a 2s. co m*/ } return ""; }
From source file:languageTools.utils.Extension.java
/** * Determines the {@link Extension} of a certain file. * * @param file/*w ww. j a v a2s. c o m*/ * The file to get the extension of. * @return The {@link Extension} of the given file, or <code>null</code> if * the file has no known extension. */ public static Extension getFileExtension(File file) { return Extension.getFileExtension(file.getName()); }
From source file:Main.java
/** * Return file display name from Uri//from w w w .j a v a 2s . c o m * * @param context Context * @param uri URI of the file * @return return file display name */ public static String getFileDisplayNameFromUri(Context context, Uri uri) { String displayName = ""; if (uri.getScheme().toString().compareTo("content") == 0) { Cursor cursor = null; try { cursor = context.getApplicationContext().getContentResolver().query(uri, null, null, null, null); if (cursor != null && cursor.moveToFirst()) { final int column_index = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DISPLAY_NAME); displayName = cursor.getString(column_index); } } finally { if (cursor != null) { cursor.close(); } } } else if (uri.getScheme().toString().compareTo("file") == 0) { final File file = new File(uri.getPath()); displayName = file.getName(); } return displayName; }
From source file:Main.java
public static String getFilename(String pathName) { File file = new File(pathName); if (!file.exists()) { return ""; }//from www. j av a2 s . c o m return file.getName(); }
From source file:Main.java
private static void copyFileOrDirectory(File source, File destination) throws IOException { if (source.isDirectory()) { if (!destination.exists()) { destination.mkdirs();//from w w w . j a va2 s . c o m } File[] files = source.listFiles(); for (File f : files) { copyFileOrDirectory(f, new File(destination, f.getName())); } } else { copyFile(source, destination); } }
From source file:hoot.services.utils.FileUtils.java
public static File getSubFolderFromFolder(String targetFolder, String subFolderName) { File ret = null;/*w w w . j av a 2 s .c om*/ File folder = new File(targetFolder); List<File> files = (List<File>) org.apache.commons.io.FileUtils.listFilesAndDirs(folder, new NotFileFilter(TrueFileFilter.INSTANCE), DirectoryFileFilter.DIRECTORY); for (File file : files) { if (file.getName().equals(subFolderName)) { ret = file; break; } } return ret; }
From source file:it.serasoft.pdi.PDITools.java
private static void startAnalysis(File f, boolean followLinks) { String name = f.getName(); if (name.endsWith(EXT_PDI_JOB)) { ParseJob pje = new ParseJob(f, 0, followLinks); pje.parse();/* w ww.j ava 2s . co m*/ } else if (name.endsWith(EXT_PDI_TRANSFORMATION)) { ParseTransformation parseTransf = new ParseTransformation(f, 0, followLinks); parseTransf.parse(); } }