java 读取指定文件夹下的所有文件名称


	public static void main(String[] args) {
		// This is the path where the file's name you want to take.
		String path = "D:\\workspace_spring\\S2SH\\WebContent\\WEB-INF\\lib";
		getFile(path);
	}

	private static void getFile(String path) {
		// get file list where the path has
		File file = new File(path);
		// get the folder list
		File[] array = file.listFiles();

		for (int i = 0; i < array.length; i++) {
			if (array[i].isFile()) {
				// only take file name
				System.out.println( array[i].getName());
				// take file path and name
//				System.out.println(array[i]);
				// take file path and name
//				System.out.println(array[i].getPath());
			} else if (array[i].isDirectory()) {
				getFile(array[i].getPath());
			}
		}
	}

猜你喜欢

转载自1151461406.iteye.com/blog/2390569
今日推荐