java.io.File#list ( )源码实例Demo

下面列出了java.io.File#list ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: gemfirexd-oss   文件: AlterHDFSStoreDUnit.java
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();
  }
}
 
源代码2 项目: java_upgrade   文件: FilenameFilterDemo.java
@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);
}
 
源代码3 项目: QuranAndroid   文件: QuranPageReadActivity.java
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;
    }
}
 
源代码4 项目: focus-android   文件: WebViewDataTest.java
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));
        }
    }
}
 
源代码5 项目: openjdk-8-source   文件: ClassPath.java
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;
}
 
源代码6 项目: Notebook   文件: FileUtils.java
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;
}
 
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));
		}
	}
}
 
源代码8 项目: FaceSlim   文件: FileOperation.java
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();
}
 
源代码9 项目: AnimeTaste   文件: CacheUtils.java
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();
}
 
/**
 * 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());
		}
	}

}
 
源代码11 项目: kylin-on-parquet-v2   文件: ResourceToolTest.java
@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();
}
 
源代码12 项目: android_9.0.0_r45   文件: FileUtils.java
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;
    }
}
 
源代码13 项目: tddl5   文件: JE_Table.java
@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();
}
 
源代码14 项目: framework   文件: OCacheUtils.java
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();
}
 
private static boolean isDirectoryEmpty(File directory) {
	if (!directory.exists()) {
		return true;
	}
	String[] nested = directory.list();
	return nested == null || nested.length == 0;
}
 
源代码16 项目: SimplifyReader   文件: DownloadManager.java
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;
}
 
源代码17 项目: token-core-android   文件: StorageTest.java
@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());
  }
}
 
源代码18 项目: gama   文件: ModelLibraryGenerator.java
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;
}
 
源代码19 项目: Deta_DataBase   文件: SelectRowsImp.java
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;
}
 
源代码20 项目: Deta_DataBase   文件: SelectJoinRowsImp.java
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;
}