栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

比较文件名

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

比较文件名

这将帮助您获取两个路径的文件:

import java.io.File;import java.util.*;public class ListFiles {    public static void main(String[] args)     {        // First directory path here.        String path1 = ".";        // Second directory path here.        String path2 = ".";        // File class is very important.        // If you did a simple Google search        // Then you would have seen this class mentioned.        File folder1 = new File(path1);        File folder2 = new File(path2);        // It gets the list of files for you.        File[] listOfFiles1 = folder1.listFiles();         File[] listOfFiles2 = folder2.listFiles();        // We'll need these to store the file names as Strings.        ArrayList<String> fileNames1 = new ArrayList<String>();        ArrayList<String> fileNames2 = new ArrayList<String>();        // Get file names from first directory.        for (int i = 0; i < listOfFiles1.length; i++)         { if (listOfFiles1[i].isFile())  {     fileNames1.add(listOfFiles1[i].getName()); }        }        // Get file names from second directory.        for (int i = 0; i < listOfFiles2.length; i++)         { if (listOfFiles2[i].isFile())  {     fileNames2.add(listOfFiles2[i].getName()); }        }        // Now compare        // Loop through the two array lists and add your own logic.    }}

您将需要添加自己的逻辑进行比较。资源



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/516433.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号