Java recursively reads all file names under the file path and saves them as TXT documents
•
Java
<svg xmlns="http://www.w3.org/2000/svg" style="display: none;"><path <a href="https://www.jb51.cc/tag/stroke/" target="_blank" class="keywords">stroke</a>-linecap="round" d="M5,0 0,2.5 5,5z" id="raphael-marker-block" style="-webkit-tap-highlight-color: rgba(0,0);"></path></svg><p>本文用递归的<a href="https://www.jb51.cc/tag/fangfa/" target="_blank" class="keywords">方法</a>实现读取<a href="https://www.jb51.cc/tag/yige/" target="_blank" class="keywords">一个</a>路径下面的所有<a href="https://www.jb51.cc/tag/wenjian/" target="_blank" class="keywords">文件</a>并将<a href="https://www.jb51.cc/tag/wenjian/" target="_blank" class="keywords">文件</a><a href="https://www.jb51.cc/tag/mingcheng/" target="_blank" class="keywords">名称</a>保存到Txt<a href="https://www.jb51.cc/tag/wenjian/" target="_blank" class="keywords">文件</a>中,亲测可用。</p>
Recursively read all files under the file path:
Output content to (append) TXT file to save:
测试:
进行测试,读取“E:\图书\图书馆\小说杂文”下的所有文件,并将结果输出到 “C:\Users\Administrator\Desktop\fileNameList.txt”中。测试代码如下:
fileNameList = readFiles1(filePath,new ArrayList()); Sy stem.out.println(fileNameList.size()); for (int i = 0; i < fileNameList.size(); i++) { outputToTxt(fileNameList.get(i),outputPath1); } } catch (Exception e) { e.printStackTrace(); } } 测试结果如下:
这是文件路径,路径下面有一个新建文件夹和若干个txt文件,共1086个对象,新建文件夹下面共有10个txt文件,计算可得此路径下面共有1086+10-1=1095个txt个文件:
</div> <link href="https://csdnimg.cn/release/phoenix/mdeditor/markdown_views-7f770a53f2.css" rel="stylesheet">
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码