<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>机械境-信永软件工程师培训学校 &#187; java</title>
	<atom:link href="http://code.oseschool.com/index.php/archives/tag/java/feed" rel="self" type="application/rss+xml" />
	<link>http://code.oseschool.com</link>
	<description>世界：男人、女人、程序员</description>
	<lastBuildDate>Sun, 07 Mar 2010 02:43:20 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>java获取文件夹下所有子文件夹</title>
		<link>http://code.oseschool.com/index.php/archives/5</link>
		<comments>http://code.oseschool.com/index.php/archives/5#comments</comments>
		<pubDate>Tue, 18 Aug 2009 13:39:48 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://code.oseschool.com/?p=5</guid>
		<description><![CDATA[
import java.io.File;
public class travelAllFile &#123;
	public static void main&#40;String&#91;&#93; args&#41; &#123;
		String path =&#34;E:/a&#34;;
		File f = new File&#40;path&#41;;
		if&#40;f.isDirectory&#40;&#41;&#41;&#123;
			new travelAllFile&#40;&#41;.getFileName&#40;f&#41;;
		&#125;
&#160;
	&#125;
	//递归查找函数，参数为file对象
	public void getFileName&#40;File f&#41;&#123;
		//File 数组
		File&#91;&#93; files = f.listFiles&#40;&#41;;
&#160;
		for &#40;int i = 0; i &#38;lt; files.length; i++&#41; &#123;
			//递归出子目录
			if&#40;files&#91;i&#93;.isDirectory&#40;&#41;&#41;&#123;
				System.out.println&#40;&#34;子目录是：&#34;+files&#91;i&#93;.getName&#40;&#41;&#41;;
				getFileName&#40;files&#91;i&#93;&#41;;
			//递归出子文件
			&#125;else&#123;
				System.out.println&#40;files&#91;i&#93;.getName&#40;&#41;&#41;;
			&#125;
&#160;
		&#125;
	&#125;
&#125;

isDirectory()方法可以判断当前是否为文件夹
]]></description>
			<content:encoded><![CDATA[
<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.File</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> travelAllFile <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #003399;">String</span> path <span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;E:/a&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #003399;">File</span> f <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">File</span><span style="color: #009900;">&#40;</span>path<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>f.<span style="color: #006633;">isDirectory</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">new</span> travelAllFile<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getFileName</span><span style="color: #009900;">&#40;</span>f<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span>
	<span style="color: #666666; font-style: italic;">//递归查找函数，参数为file对象</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> getFileName<span style="color: #009900;">&#40;</span><span style="color: #003399;">File</span> f<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">//File 数组</span>
		<span style="color: #003399;">File</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> files <span style="color: #339933;">=</span> f.<span style="color: #006633;">listFiles</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> files.<span style="color: #006633;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #666666; font-style: italic;">//递归出子目录</span>
			<span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>files<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #006633;">isDirectory</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
				<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;子目录是：&quot;</span><span style="color: #339933;">+</span>files<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #006633;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				getFileName<span style="color: #009900;">&#40;</span>files<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #666666; font-style: italic;">//递归出子文件</span>
			<span style="color: #009900;">&#125;</span><span style="color: #000000; font-weight: bold;">else</span><span style="color: #009900;">&#123;</span>
				<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>files<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #006633;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>isDirectory()方法可以判断当前是否为文件夹</p>
]]></content:encoded>
			<wfw:commentRss>http://code.oseschool.com/index.php/archives/5/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

