List of usage examples for java.io File isFile
public boolean isFile()
From source file:io.apiman.common.config.ConfigFileConfiguration.java
/** * Returns a URL to a file with the given name inside the given directory. */// w w w . j av a 2 s. c om protected static URL findConfigUrlInDirectory(File directory, String configName) { if (directory.isDirectory()) { File cfile = new File(directory, configName); if (cfile.isFile()) { try { return cfile.toURI().toURL(); } catch (MalformedURLException e) { throw new RuntimeException(e); } } } return null; }
From source file:Main.java
/** * Returns a reference to a file with the specified name that is located * somewhere on the classpath. The code for this method is an adaptation of * code supplied by Dave Postill.// ww w. j av a2 s.c o m * * @param name * the filename. * * @return a reference to a file or <code>null if no file could be * found. */ public static File findFileOnClassPath(final String name) { final String classpath = System.getProperty("java.class.path"); final String pathSeparator = System.getProperty("path.separator"); final StringTokenizer tokenizer = new StringTokenizer(classpath, pathSeparator); while (tokenizer.hasMoreTokens()) { final String pathElement = tokenizer.nextToken(); final File directoryOrJar = new File(pathElement); final File absoluteDirectoryOrJar = directoryOrJar.getAbsoluteFile(); if (absoluteDirectoryOrJar.isFile()) { final File target = new File(absoluteDirectoryOrJar.getParent(), name); if (target.exists()) { return target; } } else { final File target = new File(directoryOrJar, name); if (target.exists()) { return target; } } } return null; }
From source file:com.adaptris.core.LogHandlerTest.java
public static void ensureDirectory(File dirOrFile) { if (dirOrFile.isFile()) { dirOrFile.delete();// ww w. java 2s. com } dirOrFile.mkdirs(); }
From source file:com.indeed.imhotep.web.config.WebApp.java
private static void cleanupTempFiles() { final String tempDirPath = System.getProperty("java.io.tmpdir"); final File tempDir = new File(tempDirPath); final File[] files = tempDir.listFiles(); if (files == null) { return;//w w w . j av a 2s . c om } int deletedCount = 0; for (final File tempFile : files) { if (tempFile.isFile() && tempFile.getName().startsWith(IQLQuery.TEMP_FILE_PREFIX)) { if (!tempFile.delete()) { log.warn("Failed to delete temp file: " + tempFile); } deletedCount++; } } if (deletedCount > 0) { log.info("Cleaned up " + deletedCount + " temp files"); } }
From source file:com.stam.batchmove.BatchMoveUtils.java
public static File findFileByName(List<File> files, String fileName) { File file = null;//from ww w.j a v a 2 s.c o m for (File f : files) { if (f.isFile()) { String fn = f.getName(); String fileNameWithoutExt = FilenameUtils.removeExtension(fn); if (fileName.equals(fn)) { file = f; break; } else if (fileName.equals(fileNameWithoutExt)) { file = f; break; } } } return file; }
From source file:de.dfki.resc28.ole.bootstrap.App.java
private static void parseFile(File file) throws IOException { if (file.isFile()) { // parse the .DAT file and create RDF models for asset and its .DAT distribution InputStream fis = new FileInputStream(file); LDrawLexer lexer = new LDrawLexer(new ANTLRInputStream(fis)); LDrawParser parser = new LDrawParser(new CommonTokenStream(lexer)); ParseTreeWalker walker = new ParseTreeWalker(); ParseTree tree = parser.file();//from w ww. ja v a 2 s . c o m walker.walk(new AssetListener(file.getName(), fGraphStore), tree); walker.walk(new LdrawDistributionListener(file.getName(), fGraphStore), tree); // // FIXME: create users // walker.walk(new UserListener(file.getName(), fGraphStore), tree); // add asset to repo Resource asset = fRepoModel .createResource(Util.joinPath(fAssetBaseUri, FilenameUtils.getBaseName(file.getName()))); fRepoModel.add(fRepo, DCAT.dataset, asset); // close InputStream fis.close(); } }
From source file:c3.ops.priam.utils.SystemUtils.java
public static void createDirs(String location) { File dirFile = new File(location); if (dirFile.exists() && dirFile.isFile()) { dirFile.delete();/*from w ww. j a v a2 s.c o m*/ dirFile.mkdirs(); } else if (!dirFile.exists()) dirFile.mkdirs(); }
From source file:Main.java
/** * get the FileOutputStream/*from ww w.ja va2s. c o m*/ * @param filePath the filePath must contain head "/" * @return */ public static FileOutputStream getFileOutputStream(String filePath) { FileOutputStream fouts = null; File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + filePath.trim()); if (file.exists() && file.isFile()) { try { fouts = new FileOutputStream(file); Log.d("Ragnarok", "get the fouts path = " + file.getAbsolutePath()); return fouts; } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { try { File fileDirs = new File(file.getParent()); fileDirs.mkdirs(); //Log.d(LOG_TAG, "make the fileDirs " + fileDirs.getPath()); //file.createNewFile(); //Log.d("Ragnarok", "create a new file name " + file.getName()); Log.d("Ragnarok", "file path " + file.getAbsolutePath()); synchronized (file) { file.createNewFile(); fouts = new FileOutputStream(file); return fouts; } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return null; }
From source file:com.technophobia.substeps.runner.syntax.FileUtils.java
public static Collection<File> getFiles(final File fFile, final String extension) { // the parameter might be a dir or a single file final Collection<File> files; if (fFile.isFile()) { List<File> fileList = new ArrayList<>(); fileList.add(fFile);//from ww w . ja va 2 s . co m files = Collections.unmodifiableCollection(fileList); } else { files = org.apache.commons.io.FileUtils.listFiles(fFile, new String[] { extension }, true); } return files; }
From source file:com.zyz.mobile.file.FileClipboard.java
/** * Delete the specified file.//ww w .j av a 2s . c o m * * @param file the file to be deleted */ public static void deleteFile(File file) throws IOException { if (file.isFile()) { file.delete(); } else { FileUtils.deleteDirectory(file); } }