java se之File类

 

遍历某个目录路径下的所有文件并打印输出:

package com.led.file;

import java.io.File;

public class File_List {
    
    public static void listFiles(File file){
        
        if(file!=null){
            if(file.isDirectory()){//是目录
                File[] f=file.listFiles();
                if(f!=null){
                    for(int i=0;i<f.length;i++){
                            listFiles(f[i]);//递归调用遍历文件
                    }
                }
            }else{//是文件
                System.out.println(file);//打印文件路径
            }
        }
    }
    public static void main(String[] args) {
        File file=new File("E://迅雷下载//mysql-connector-java-3.1.12");
        listFiles(file);
    }

}

结果:

E:\迅雷下载\mysql-connector-java-3.1.12\build.xml
E:\迅雷下载\mysql-connector-java-3.1.12\CHANGES
E:\迅雷下载\mysql-connector-java-3.1.12\COPYING
E:\迅雷下载\mysql-connector-java-3.1.12\debug\mysql-connector-java-3.1.12-bin-g.jar
E:\迅雷下载\mysql-connector-java-3.1.12\docs\connector-j.html
E:\迅雷下载\mysql-connector-java-3.1.12\docs\connector-j.pdf
E:\迅雷下载\mysql-connector-java-3.1.12\docs\README
E:\迅雷下载\mysql-connector-java-3.1.12\docs\README.txt
E:\迅雷下载\mysql-connector-java-3.1.12\EXCEPTIONS-CONNECTOR-J
E:\迅雷下载\mysql-connector-java-3.1.12\mysql-connector-java-3.1.12-bin.jar
E:\迅雷下载\mysql-connector-java-3.1.12\README
E:\迅雷下载\mysql-connector-java-3.1.12\README.txt
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\AssertionFailedException.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\Blob.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\BlobFromLocator.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\Buffer.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\ByteArrayBuffer.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\CallableStatement.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\ChannelBuffer.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\CharsetMapping.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\Charsets.properties
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\Clob.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\CommunicationsException.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\CompressedInputStream.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\configs\3-0-Compat.properties
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\configs\clusterBase.properties
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\configs\fullDebug.properties
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\configs\maxPerformance.properties
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\configs\solarisMaxPerformance.properties
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\Connection.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\ConnectionFeatureNotAvailableException.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\ConnectionProperties.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\ConnectionPropertiesTransform.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\Constants.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\DatabaseMetaData.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\DocsConnectionPropsHelper.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\Driver.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\EscapeProcessor.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\EscapeProcessorResult.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\EscapeTokenizer.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\ExportControlled.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\Field.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\integration\c3p0\MysqlConnectionTester.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\integration\jboss\ExtendedMysqlExceptionSorter.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\integration\jboss\MysqlValidConnectionChecker.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\jdbc2\optional\CallableStatementWrapper.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\jdbc2\optional\ConnectionWrapper.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\jdbc2\optional\MysqlConnectionPoolDataSource.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\jdbc2\optional\MysqlDataSource.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\jdbc2\optional\MysqlDataSourceFactory.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\jdbc2\optional\MysqlPooledConnection.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\jdbc2\optional\PreparedStatementWrapper.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\jdbc2\optional\StatementWrapper.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\jdbc2\optional\WrapperBase.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\LicenseConfiguration.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\LocalizedErrorMessages.properties
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\log\Jdk14Logger.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\log\Log.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\log\Log4JLogger.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\log\LogFactory.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\log\LogUtils.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\log\NullLogger.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\log\StandardLogger.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\Messages.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\MiniAdmin.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\MysqlDataTruncation.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\MysqlDefs.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\MysqlErrorNumbers.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\MysqlIO.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\MysqlParameterMetadata.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\MysqlSavepoint.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\NamedPipeSocketFactory.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\NonRegisteringDriver.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\NonRegisteringReplicationDriver.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\NotImplemented.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\NotUpdatable.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\OutputStreamWatcher.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\PacketTooBigException.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\PreparedStatement.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\profiler\ProfileEventSink.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\profiler\ProfilerEvent.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\ReplicationConnection.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\ReplicationDriver.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\ResultSet.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\ResultSetMetaData.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\RowData.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\RowDataDynamic.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\RowDataStatic.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\Security.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\ServerPreparedStatement.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\SingleByteCharsetConverter.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\SocketFactory.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\SQLError.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\StandardSocketFactory.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\Statement.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\StringUtils.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\TimeUtil.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\trace\Tracer.aj
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\UpdatableResultSet.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\util\BaseBugReport.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\util\ErrorMappingsDocGenerator.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\util\LRUCache.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\util\PropertiesDocGenerator.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\util\ReadAheadInputStream.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\util\ResultSetUtil.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\util\ServerController.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\util\TimezoneDump.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\util\VersionFSHierarchyMaker.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\Util.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\WatchableOutputStream.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\WatchableWriter.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\webapp\images\mysql-logo.png
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\webapp\style\style.css
E:\迅雷下载\mysql-connector-java-3.1.12\src\com\mysql\jdbc\WriterWatcher.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\doc\sources\connPropsToDocbook.xsl
E:\迅雷下载\mysql-connector-java-3.1.12\src\doc\sources\errorMapToDocbook.xsl
E:\迅雷下载\mysql-connector-java-3.1.12\src\doc\sources\placeholder.txt
E:\迅雷下载\mysql-connector-java-3.1.12\src\lib\ant-contrib.jar
E:\迅雷下载\mysql-connector-java-3.1.12\src\lib\aspectjrt.jar
E:\迅雷下载\mysql-connector-java-3.1.12\src\lib\aspectjtools.jar
E:\迅雷下载\mysql-connector-java-3.1.12\src\lib\c3p0-0.8.5-pre8.jar
E:\迅雷下载\mysql-connector-java-3.1.12\src\lib\c3p0-LICENSE
E:\迅雷下载\mysql-connector-java-3.1.12\src\lib\jboss-common-jdbc-wrapper.jar
E:\迅雷下载\mysql-connector-java-3.1.12\src\lib\jboss-lgpl.txt
E:\迅雷下载\mysql-connector-java-3.1.12\src\lib\jdbc2_0-stdext.jar
E:\迅雷下载\mysql-connector-java-3.1.12\src\lib\jta-spec1_0_1.jar
E:\迅雷下载\mysql-connector-java-3.1.12\src\lib\junit.jar
E:\迅雷下载\mysql-connector-java-3.1.12\src\lib\LICENSE-AspectJ.html
E:\迅雷下载\mysql-connector-java-3.1.12\src\lib\log4j-1.2.9.jar
E:\迅雷下载\mysql-connector-java-3.1.12\src\org\gjt\mm\mysql\Driver.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\testsuite\BaseTestCase.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\testsuite\perf\BasePerfTest.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\testsuite\perf\LoadStorePerfTest.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\testsuite\perf\RetrievalPerfTest.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\testsuite\regression\AppletRegressionTest.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\testsuite\regression\BlobRegressionTest.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\testsuite\regression\CachedRowsetTest.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\testsuite\regression\CallableStatementRegressionTest.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\testsuite\regression\ConnectionRegressionTest.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\testsuite\regression\DataSourceRegressionTest.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\testsuite\regression\EscapeProcessorRegressionTest.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\testsuite\regression\MetaDataRegressionTest.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\testsuite\regression\MicroPerformanceRegressionTest.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\testsuite\regression\NumbersRegressionTest.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\testsuite\regression\PooledConnectionRegressionTest.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\testsuite\regression\ResultSetRegressionTest.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\testsuite\regression\StatementRegressionTest.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\testsuite\regression\StressRegressionTest.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\testsuite\regression\StringRegressionTest.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\testsuite\regression\SubqueriesRegressionTest.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\testsuite\requiresNonRedists\CachedRowSetRegressionTest.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\testsuite\simple\BlobTest.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\testsuite\simple\CallableStatementTest.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\testsuite\simple\CharsetTests.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\testsuite\simple\ConnectionTest.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\testsuite\simple\DataSourceTest.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\testsuite\simple\DateTest.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\testsuite\simple\EscapeProcessingTest.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\testsuite\simple\MetadataTest.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\testsuite\simple\MiniAdminTest.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\testsuite\simple\NumbersTest.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\testsuite\simple\ServerControllerTest.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\testsuite\simple\SimpleTransformer.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\testsuite\simple\SSLTest.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\testsuite\simple\StatementsTest.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\testsuite\simple\TransactionTest.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\testsuite\simple\TraversalTest.java
E:\迅雷下载\mysql-connector-java-3.1.12\src\testsuite\simple\UpdatabilityTest.java

 

posted on 2016-12-04 22:52  Javanumberone  阅读(232)  评论(0编辑  收藏  举报

导航