List of usage examples for java.io File list
public String[] list()
From source file:org.jboss.as.test.integration.web.annotationsmodule.WebModuleDeploymentTestCase.java
private static void deleteRecursively(File file) { if (file.exists()) { if (file.isDirectory()) { for (String name : file.list()) { deleteRecursively(new File(file, name)); }/*w w w . ja v a 2 s. c o m*/ } file.delete(); } }
From source file:fr.gael.dhus.service.UploadService.java
private static boolean deleteDir(File dir) { if (dir.isDirectory()) { String[] children = dir.list(); for (int i = 0; i < children.length; i++) { boolean success = deleteDir(new File(dir, children[i])); if (!success) { return false; }/*w ww . jav a 2 s. c o m*/ } } // The directory is now empty so delete it return dir.delete(); }
From source file:mpimp.assemblxweb.util.J5FileUtils.java
public static void deleteTuSubunitRelatedFiles(TuSubunit tuSubunit, AssemblXWebModel model) throws IOException { if (tuSubunit.getSequenceFileLoaded()) { // check first if the sequence file is not used by another subunit // as well List<TuSubunit> tuSubunits = tuSubunit.getParentTuUnit().getTuSubunits(); int counter = 0; for (TuSubunit currentTuSubunit : tuSubunits) { if (currentTuSubunit.getSequenceFileName() != null && currentTuSubunit.getSequenceFileName().equals(tuSubunit.getSequenceFileName())) { counter++;/*from www . j a v a 2 s. c om*/ } } if (counter > 1) { return; // sequence file is used more than once, so we must // not delete it along with the subunit } String sequenceFilePathName = model.getWorkingDirectory() + File.separator + model.getCurrentTuUnit().getTuDirectoryName() + File.separator + AssemblXWebProperties.getInstance().getProperty("sequenceFileDirectory") + File.separator + tuSubunit.getSequenceFileName(); Files.deleteIfExists(Paths.get(sequenceFilePathName)); String sequencesDirPath = model.getWorkingDirectory() + File.separator + model.getCurrentTuUnit().getTuDirectoryName() + File.separator + AssemblXWebProperties.getInstance().getProperty("sequenceFileDirectory"); File sequencesDir = new File(sequencesDirPath); if (sequencesDir.isDirectory() && sequencesDir.list().length == 0) { Files.delete(Paths.get(sequencesDirPath)); } String tuDirectoryPath = model.getWorkingDirectory() + File.separator + model.getCurrentTuUnit().getTuDirectoryName(); File tuDirectory = new File(tuDirectoryPath); if (tuDirectory.isDirectory() && tuDirectory.list().length == 0) { Files.delete(Paths.get(tuDirectoryPath)); } } }
From source file:Util.java
/** * Deletes a file or directory, allowing recursive directory deletion. This is an * improved version of File.delete() method. *//* w w w . j a v a 2 s . c o m*/ public static boolean delete(String filePath, boolean recursive) { File file = new File(filePath); if (!file.exists()) { return true; } if (!recursive || !file.isDirectory()) return file.delete(); String[] list = file.list(); for (int i = 0; i < list.length; i++) { if (!delete(filePath + File.separator + list[i], true)) return false; } return file.delete(); }
From source file:com.amalto.workbench.editors.XSDDriver.java
public static boolean deleteContent(File file) { assert (file != null); String[] children = file.list(); if (children == null) { return true; }// w w w .ja va 2 s .c o m for (int i = 0; i < children.length; i++) { if (!XSDDriver.delete(new File(file, children[i]))) { return false; } } return true; }
From source file:com.amalto.workbench.editors.XSDDriver.java
public static boolean deleteDir(File dir) { if (dir.isDirectory()) { String[] children = dir.list(); for (int i = 0; i < children.length; i++) { boolean success = deleteDir(new File(dir, children[i])); if (!success) { return false; }//from www . j a v a 2 s. c o m } } return dir.delete(); }
From source file:com.glaf.core.config.ViewProperties.java
public static void reload() { if (!loading.get()) { InputStream inputStream = null; try {/*w w w . jav a 2 s .com*/ loading.set(true); String config = SystemProperties.getConfigRootPath() + "/conf/props/views"; File directory = new File(config); if (directory.exists() && directory.isDirectory()) { String[] filelist = directory.list(); if (filelist != null) { for (int i = 0, len = filelist.length; i < len; i++) { String filename = config + "/" + filelist[i]; File file = new File(filename); if (file.isFile() && file.getName().endsWith(".properties")) { inputStream = new FileInputStream(file); Properties p = PropertiesUtils.loadProperties(inputStream); if (p != null) { Enumeration<?> e = p.keys(); while (e.hasMoreElements()) { String key = (String) e.nextElement(); String value = p.getProperty(key); properties.setProperty(key, value); properties.setProperty(key.toLowerCase(), value); properties.setProperty(key.toUpperCase(), value); } } IOUtils.closeStream(inputStream); } } } } } catch (Exception ex) { throw new RuntimeException(ex); } finally { loading.set(false); IOUtils.closeStream(inputStream); } } }
From source file:com.insightaction.util.DataLoader.java
private static void loadToStaging(DSLContext create) throws IOException { File dir = new File("data"); Collection<String> files = Arrays.asList(dir.list()); for (String file : files) { System.out.println(file); CSVReader reader = new CSVReader(new FileReader("data/" + file)); String[] nextLine;/* w w w. j a v a2 s . com*/ while ((nextLine = reader.readNext()) != null) { /* Prevent index out of bounds */ nextLine = ArrayUtils.addAll(nextLine, new String[20]); CsvImportRecord record = create.newRecord(CSV_IMPORT); record.setFilename(file); record.setStatus(PENDING); record.setImportdate(getCurrentTimestamp()); record.setA(nextLine[0]); record.setB(nextLine[1]); record.setC(nextLine[2]); record.setD(nextLine[3]); record.setE(nextLine[4]); record.setF(nextLine[5]); record.setG(nextLine[6]); record.setH(nextLine[7]); record.setI(nextLine[8]); record.setJ(nextLine[8]); record.setK(nextLine[10]); record.setL(nextLine[11]); record.setM(nextLine[12]); record.setN(nextLine[13]); record.setO(nextLine[14]); record.setP(nextLine[15]); record.setQ(nextLine[16]); record.setR(nextLine[17]); record.setS(nextLine[18]); record.setT(nextLine[19]); record.store(); } } }
From source file:edu.iu.daal_kmeans.regroupallgather.KMUtil.java
private static void delete(File file) { if (file.isDirectory()) { String fileList[] = file.list(); if (fileList.length == 0) { System.out.println("Deleting Directory : " + file.getPath()); file.delete();//from w w w . j a v a 2 s. co m } else { int size = fileList.length; for (int i = 0; i < size; i++) { String fileName = fileList[i]; System.out.println("File path : " + file.getPath() + " and name :" + fileName); String fullPath = file.getPath() + "/" + fileName; File fileOrFolder = new File(fullPath); System.out.println("Full Path :" + fileOrFolder.getPath()); delete(fileOrFolder); } } } else { System.out.println("Deleting file : " + file.getPath()); file.delete(); } }
From source file:com.appeligo.lucene.DidYouMeanIndexer.java
public static void createDefaultSpellIndex(String indexDir, String spellDir) throws IOException { String newSpellDir = spellDir + ".new"; File newSpellDirFile = new File(newSpellDir); if (newSpellDirFile.exists()) { String[] dirFiles = newSpellDirFile.list(); for (String dirFile : dirFiles) { File f = new File(newSpellDirFile, dirFile); if (!f.delete()) { throw new IOException("Could not delete " + f.getAbsolutePath()); }/* ww w .jav a 2 s .co m*/ } if (!newSpellDirFile.delete()) { throw new IOException("Could not delete " + newSpellDirFile.getAbsolutePath()); } } /* This was for the original programIndex, but we found out that stemming was bad, and you get better * spelling suggestions if you can specify a single field, so we combined them. for (String field : new String[]{"text","description","programTitle", "episodeTitle", "credits", "genre"}) { createSpellIndex(field, FSDirectory.getDirectory(indexDir), FSDirectory.getDirectory(newSpellDir)); } */ createSpellIndex("compositeField", FSDirectory.getDirectory(indexDir), FSDirectory.getDirectory(newSpellDir)); String oldSpellDir = spellDir + ".old"; File oldSpellDirFile = new File(oldSpellDir); if (oldSpellDirFile.exists()) { String[] dirFiles = oldSpellDirFile.list(); for (String dirFile : dirFiles) { File f = new File(oldSpellDirFile, dirFile); if (!f.delete()) { throw new IOException("Could not delete " + f.getAbsolutePath()); } } if (!oldSpellDirFile.delete()) { throw new IOException("Could not delete " + oldSpellDirFile.getAbsolutePath()); } } File spellDirFile = new File(spellDir); if (spellDirFile.exists() && !spellDirFile.renameTo(oldSpellDirFile)) { throw new IOException("could not rename " + spellDirFile.getAbsolutePath() + " to " + oldSpellDirFile.getAbsolutePath()); } /* there is some small risk here that someone might try to get the spell index when the file isn't there yet */ /* I don't know of any way to really synchronize that from this class, and the risk is minor, unlikely, and not catastrophic */ spellDirFile = new File(spellDir); if (!newSpellDirFile.renameTo(spellDirFile)) { // What really bugs me is you can't close a SpellChecker, and I think that prevents us from renaming // the spell index directory (at least on Windows Vista), so let's copy the files instead /* throw new IOException("could not rename "+newSpellDirFile.getAbsolutePath()+" to "+spellDirFile.getAbsolutePath()); */ if (!spellDirFile.mkdir()) { throw new IOException("Couldn't make directory " + spellDirFile.getAbsolutePath()); } String[] dirFiles = newSpellDirFile.list(); for (String dirFile : dirFiles) { File f = new File(newSpellDirFile, dirFile); File toF = new File(spellDirFile, dirFile); InputStream is = new BufferedInputStream(new FileInputStream(f.getAbsolutePath())); OutputStream os = new BufferedOutputStream(new FileOutputStream(toF.getAbsolutePath())); int b; while ((b = is.read()) != -1) { os.write(b); } is.close(); os.close(); /* I'd like to do this, but the same reason the rename won't work is why this * won't work... this current program still has one or more of the files open. if (!f.delete()) { throw new IOException("Could not delete "+f.getAbsolutePath()); } } if (!newSpellDirFile.delete()) { throw new IOException("Could not delete "+newSpellDirFile.getAbsolutePath()); } */ } } }