Java Code Examples for java.io.File#list()
The following examples show how to use
java.io.File#list() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AlterHDFSStoreDUnit.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
private void delete(File file) { if (!file.exists()) { return; } if (file.isDirectory()) { if (file.list().length == 0) { file.delete(); } else { File[] files = file.listFiles(); for (File f : files) { delete(f); } file.delete(); } } else { file.delete(); } }
Example 2
Source File: ClassPath.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
String[] getFiles(String subdir) { String files[] = (String[]) subdirs.get(subdir); if (files == null) { // search the directory, exactly once File sd = new File(dir.getPath(), subdir); if (sd.isDirectory()) { files = sd.list(); if (files == null) { // should not happen, but just in case, fail silently files = new String[0]; } if (files.length == 0) { String nonEmpty[] = { "" }; files = nonEmpty; } } else { files = new String[0]; } subdirs.put(subdir, files); } return files; }
Example 3
Source File: FilenameFilterDemo.java From java_upgrade with MIT License | 6 votes |
@SuppressWarnings("ConstantConditions") public static void main(String[] args) { File directory = new File("src/main/java"); // Print all files in directory String[] fileNames = directory.list(); System.out.println(Arrays.asList(fileNames)); // Print only Java source files in directory fileNames = directory.list(new FilenameFilter() { @Override public boolean accept(File dir, String name) { return name.endsWith(".java"); } }); System.out.println(Arrays.asList(fileNames)); fileNames = directory.list((dir, name) -> name.endsWith(".java")); System.out.println(Arrays.asList(fileNames)); Arrays.stream(fileNames) .forEach(s -> System.out.println("The current strings is " + s)); Arrays.stream(fileNames) .forEach(System.out::println); }
Example 4
Source File: QuranPageReadActivity.java From QuranAndroid with GNU General Public License v3.0 | 6 votes |
public static boolean deleteDir(File dir) { if (dir != null && 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; } } return dir.delete(); } else if (dir != null && dir.isFile()) { return dir.delete(); } else { return false; } }
Example 5
Source File: WebViewDataTest.java From focus-android with Mozilla Public License 2.0 | 6 votes |
private void assertNoTraces(File directory) throws IOException { for (final String name : directory.list()) { final File file = new File(directory, name); if (file.isDirectory()) { assertNoTraces(file); continue; } if (NO_TRACES_IGNORE_LIST.contains(name)) { Log.d(LOGTAG, "assertNoTraces: Ignoring file '" + name + "'..."); continue; } if (!file.exists()) { continue; } final String content = TestHelper.readFileToString(file); for (String trace : TEST_TRACES) { assertFalse("File '" + name + "' should not contain any traces of browser session (" + trace + ", path=" + file.getAbsolutePath() + ")", content.contains(trace)); } } }
Example 6
Source File: ResourceToolTest.java From kylin-on-parquet-v2 with Apache License 2.0 | 5 votes |
@After public void after() throws Exception { FileUtils.deleteQuietly(new File(LocalFileMetadataTestCase.LOCALMETA_TEST_DATA + FILE_1)); FileUtils.deleteQuietly(new File(LocalFileMetadataTestCase.LOCALMETA_TEST_DATA + FILE_2)); File directory = new File(dstPath); try { FileUtils.deleteDirectory(directory); } catch (IOException e) { if (directory.exists() && directory.list().length > 0) throw new IllegalStateException("Can't delete directory " + directory, e); } this.cleanupTestMetadata(); }
Example 7
Source File: ModelLibraryGenerator.java From gama with GNU General Public License v3.0 | 5 votes |
private static ArrayList<String> getSectionName() { final ArrayList<String> result = new ArrayList<>(); for (final String path : inputPathToModelLibrary) { final File directory = new File(path); final String[] sectionNames = directory.list((current, name) -> new File(current, name).isDirectory()); for (final String sectionName : sectionNames) { result.add(sectionName); } } return result; }
Example 8
Source File: StorageTest.java From token-core-android with Apache License 2.0 | 5 votes |
@Test public void testImportETHWalletFromPrivate() { Metadata metadata = new Metadata(ChainType.ETHEREUM, Network.MAINNET, "name", "passwordHint"); metadata.setSource(Metadata.FROM_PRIVATE); WalletManager.importWalletFromPrivateKey(metadata, SampleKey.PRIVATE_KEY_STRING, SampleKey.PASSWORD, true); File keystoreDir = new File(KEYSTORE_DIR); Assert.assertNotNull(keystoreDir.list()); String walletFilePath = keystoreDir.list()[0]; Assert.assertNotNull(walletFilePath); String fileContent = readFileContent(walletFilePath); try { JSONObject jsonObject = new JSONObject(fileContent); Assert.assertNotNull(jsonObject); Assert.assertNotNull(jsonObject.getString("address")); Assert.assertNotNull(jsonObject.getJSONObject("crypto")); JSONObject metadataObj = jsonObject.getJSONObject("imTokenMeta"); assertNotNull(metadataObj); assertEquals(ChainType.ETHEREUM, metadataObj.getString("chainType")); assertNotEquals(0L, metadataObj.getLong("timestamp")); assertEquals(Metadata.V3, metadataObj.getString("walletType")); assertEquals(Metadata.NORMAL, metadataObj.getString("mode")); assertEquals(Metadata.FROM_PRIVATE, metadataObj.getString("source")); } catch (JSONException e) { Assert.fail("Some error happened, exception: " + e.getMessage()); } }
Example 9
Source File: DownloadManager.java From SimplifyReader with Apache License 2.0 | 5 votes |
private HashMap<String, DownloadInfo> getNewDownloadedData() { downloadedData = new HashMap<String, DownloadInfo>(); if ((sdCard_list = SDCardManager.getExternalStorageDirectory()) == null) { return downloadedData; } for (int j = 0; j < sdCard_list.size(); j++) { File dir = new File(sdCard_list.get(j).path + YoukuPlayerApplication.getDownloadPath()); if (!dir.exists()) continue; String[] dirs = dir.list(); for (int i = dirs.length - 1; i >= 0; i--) { String vid = dirs[i]; final DownloadInfo d = getDownloadInfoBySavePath(sdCard_list .get(j).path + YoukuPlayerApplication.getDownloadPath() + vid + "/"); if (d != null && d.getState() == DownloadInfo.STATE_FINISH) { downloadedData.put(d.videoid, d); if (d.segCount != d.segsSeconds.length) { new Thread() { public void run() { try { DownloadUtils.getDownloadData(d); downloadedData.put(d.videoid, d); DownloadUtils.makeDownloadInfoFile(d); DownloadUtils.makeM3U8File(d); } catch (Exception e) { } }; }.start(); } } } } return downloadedData; }
Example 10
Source File: FsCheckpointStateOutputStreamTest.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
private static boolean isDirectoryEmpty(File directory) { if (!directory.exists()) { return true; } String[] nested = directory.list(); return nested == null || nested.length == 0; }
Example 11
Source File: OCacheUtils.java From framework with GNU Affero General Public License v3.0 | 5 votes |
public static boolean deleteDir(File dir) { if (dir != null && 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; } } } return dir.delete(); }
Example 12
Source File: JE_Table.java From tddl5 with Apache License 2.0 | 5 votes |
@SuppressWarnings("unused") 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; } } } // 目录此时为空,可以删除 return dir.delete(); }
Example 13
Source File: FileUtils.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
public static @NonNull String[] listOrEmpty(@Nullable File dir) { if (dir == null) return EmptyArray.STRING; final String[] res = dir.list(); if (res != null) { return res; } else { return EmptyArray.STRING; } }
Example 14
Source File: FileUtils.java From Notebook with Apache License 2.0 | 5 votes |
public static int deleteBlankPath(String path) { File f = new File(path); if (!f.canWrite()) { return 1; } if (f.list() != null && f.list().length > 0) { return 2; } if (f.delete()) { return 0; } return 3; }
Example 15
Source File: SymbolnamePreprocessor.java From symja_android_library with GNU General Public License v3.0 | 5 votes |
/** * Generate Java files (*.java) from Symja rule files (*.m) * * @param sourceLocation source directory for rule (*.m) files * @param ignoreTimestamp if <code>false</code> only change the target file (*.java), if the source file (*.m) has a newer time * stamp than the target file. */ public static void generateFunctionStrings1(final File sourceLocation, boolean ignoreTimestamp) { if (sourceLocation.exists()) { // Get the list of the files contained in the package final String[] files = sourceLocation.list(); if (files != null) { StringBuilder buffer = new StringBuilder(16000); for (int i = 0; i < files.length; i++) { // we are only interested in .java files if (files[i].endsWith(".java")) { String className = files[i].substring(0, files[i].length() - 5); String lcClassName = className.length() == 1 ? className : className.toLowerCase(); // public final static ISymbol Collect = // initFinalSymbol(Config.PARSER_USE_LOWERCASE_SYMBOLS ? // "collect" : "Collect", // new org.matheclipse.core.builtin.function.Collect()); buffer.append("public final static ISymbol "); buffer.append(className); buffer.append(" = initFinalSymbol(\n"); buffer.append(" Config.PARSER_USE_LOWERCASE_SYMBOLS ? \"" + lcClassName + "\" : \"" + className + "\",\n"); buffer.append(" new org.matheclipse.core.builtin.function."); buffer.append(className); buffer.append("());\n"); } } System.out.println(buffer.toString()); } } }
Example 16
Source File: CacheUtils.java From AnimeTaste with MIT License | 5 votes |
public static boolean deleteDir(File dir) { if (dir != null && 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; } } } return dir.delete(); }
Example 17
Source File: FileOperation.java From FaceSlim with GNU General Public License v2.0 | 5 votes |
private static boolean deleteDir(File dir) { if (dir == null) return false; if (dir.isDirectory()) { String[] children = dir.list(); for (String child : children) { boolean success = deleteDir(new File(dir, child)); if (!success) return false; } } return dir.delete(); }
Example 18
Source File: ProcessPythonEnvironmentManagerTest.java From flink with Apache License 2.0 | 5 votes |
private static void assertFileEquals(File expectedFile, File actualFile, boolean checkUnixMode) throws IOException, NoSuchAlgorithmException { assertTrue(actualFile.exists()); assertTrue(expectedFile.exists()); if (expectedFile.getAbsolutePath().equals(actualFile.getAbsolutePath())) { return; } if (isUnix && checkUnixMode) { Set<PosixFilePermission> expectedPerm = Files.getPosixFilePermissions(Paths.get(expectedFile.toURI())); Set<PosixFilePermission> actualPerm = Files.getPosixFilePermissions(Paths.get(actualFile.toURI())); assertEquals(expectedPerm, actualPerm); } if (expectedFile.isDirectory()) { assertTrue(actualFile.isDirectory()); String[] expectedSubFiles = expectedFile.list(); assertArrayEquals(expectedSubFiles, actualFile.list()); if (expectedSubFiles != null) { for (String fileName : expectedSubFiles) { assertFileEquals( new File(expectedFile.getAbsolutePath(), fileName), new File(actualFile.getAbsolutePath(), fileName)); } } } else { assertEquals(expectedFile.length(), actualFile.length()); if (expectedFile.length() > 0) { assertTrue(org.apache.commons.io.FileUtils.contentEquals(expectedFile, actualFile)); } } }
Example 19
Source File: SelectJoinRowsImp.java From Deta_DataBase with Apache License 2.0 | 4 votes |
public static Object selectRowsByAttributesOfJoinCondition(Map<String, Object> object) throws IOException { if(!object.containsKey("recordRows")) { Map<String, Boolean> recordRows = new ConcurrentHashMap<>(); object.put("recordRows", recordRows); } Spec spec = new Spec(); spec.setCulumnTypes(new ConcurrentHashMap<String, String>()); String objectType = ""; List<Map<String, Object>> output = new ArrayList<>(); //�������ݿ� String DBPath = CacheManager.getCacheInfo("DBPath").getValue().toString() + "/" + object.get("joinBaseName").toString(); //������ File fileDBPath = new File(DBPath); if (fileDBPath.isDirectory()) { String DBTablePath = DBPath + "/" + object.get("joinTableName").toString(); File fileDBTable = new File(DBTablePath); if (fileDBTable.isDirectory()) { String DBTableCulumnPath = DBTablePath + "/spec"; File fileDBTableCulumn = new File(DBTableCulumnPath); if (fileDBTableCulumn.isDirectory()) { //��ȡ�����ݸ�ʽ String[] fileList = fileDBTableCulumn.list(); for(int i=0; i<fileList.length; i++) { File readDBTableSpecCulumnFile = new File(DBTableCulumnPath + "/" + fileList[0] + "/value.lyg"); BufferedReader reader = new BufferedReader(new FileReader(readDBTableSpecCulumnFile)); String tempString = null; while ((tempString = reader.readLine()) != null) { objectType = tempString; } reader.close(); spec.setCulumnType(fileList[i], objectType); } List<String[]> conditionValues = (List<String[]>) object.get("condition"); Iterator<String[]> iterator = conditionValues.iterator(); while(iterator.hasNext()) { boolean overMap = output.size() == 0? false: true; String[] conditionValueArray = iterator.next(); String type = conditionValueArray[1]; boolean andMap = type.equalsIgnoreCase("and")?true:false; for(int i = 2; i < conditionValueArray.length; i++) { String[] sets = conditionValueArray[i].split("\\|"); if(overMap && andMap) { ProcessConditionPLSQL.processMap(sets, output, DBTablePath);//1 }else if(DetaDBBufferCacheManager.dbCache){ ProcessConditionPLSQL.processCache(sets, output, object.get("joinTableName").toString() , object.get("joinBaseName").toString(), object);//1 }else { ProcessConditionPLSQL.processTable(sets, output, DBTablePath, object);//1 } } } } } } return output; }
Example 20
Source File: SelectRowsImp.java From Deta_DataBase with Apache License 2.0 | 4 votes |
public static Object selectRowsByAttributesOfCondition(Map<String, Object> object) throws IOException { if(!object.containsKey("recordRows")) { Map<String, Boolean> recordRows = new ConcurrentHashMap<>(); object.put("recordRows", recordRows); } Spec spec = new Spec(); spec.setCulumnTypes(new ConcurrentHashMap<String, String>()); String objectType = ""; List<Map<String, Object>> output = new ArrayList<>(); //�������ݿ� String DBPath = CacheManager.getCacheInfo("DBPath").getValue().toString() + "/" + object.get("baseName").toString(); //������ File fileDBPath = new File(DBPath); if (fileDBPath.isDirectory()) { String DBTablePath = DBPath + "/" + object.get("tableName").toString(); File fileDBTable = new File(DBTablePath); if (fileDBTable.isDirectory()) { String DBTableCulumnPath = DBTablePath + "/spec"; File fileDBTableCulumn = new File(DBTableCulumnPath); if (fileDBTableCulumn.isDirectory()) { //��ȡ�����ݸ�ʽ String[] fileList = fileDBTableCulumn.list(); for(int i=0; i<fileList.length; i++) { File readDBTableSpecCulumnFile = new File(DBTableCulumnPath + "/" + fileList[0]+"/value.lyg"); BufferedReader reader = new BufferedReader(new FileReader(readDBTableSpecCulumnFile)); String tempString = null; while ((tempString = reader.readLine()) != null) { objectType = tempString; } reader.close(); spec.setCulumnType(fileList[i], objectType); } List<String[]> conditionValues = (List<String[]>) object.get("condition"); Iterator<String[]> iterator = conditionValues.iterator(); while(iterator.hasNext()) { boolean overMap = output.size() == 0? false: true; String[] conditionValueArray = iterator.next(); String type = conditionValueArray[1]; boolean andMap = type.equalsIgnoreCase("and")?true:false; for(int i = 2; i < conditionValueArray.length; i++) { String[] sets = conditionValueArray[i].split("\\|"); if(overMap && andMap) { ProcessConditionPLSQL.processMap(sets, output, DBTablePath);//1 }else if(DetaDBBufferCacheManager.dbCache){ ProcessConditionPLSQL.processCache(sets, output, object.get("tableName").toString() , object.get("baseName").toString(), object);//1 }else { ProcessConditionPLSQL.processTable(sets, output, DBTablePath, object);//1 } } } } } } return output; }