slf4j 获取 col 存在 style logger pos pri clas
JAVA 获取文件夹下所有的文件
- package com.test;
- import org.junit.Test;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import java.io.File;
- /**
- *获取文件夹下所有的文件
- */
- public class FileTest {
- private static final Logger logger = LoggerFactory.getLogger(FileTest.class);@Test public void test() {
- getFileName("d://logs//");
- }
- private void getFileName(String filePath) {
- if (null != filePath && "".equals(filePath)) {
- File file = new File(filePath);
- //判断文件或目录是否存在
- if (!file.exists()) {
- logger.info("【" + filePath + " not exists】");
- }
- //获取该文件夹下所有的文件
- File[] fileArray = file.listFiles();
- File fileName = null;
- for (int i = 0; i < fileArray.length; i++) {
- fileName = fileArray[i];
- //判断此文件是否存在
- if (fileName.isDirectory()) {
- logger.info("【目录:" + fileName.getName() + "】");
- } else {
- logger.info(fileName.getName());
- }
- }
- }
- }
- }
来源: http://www.bubuko.com/infodetail-2450050.html