目录

  • 一、工具类
  • 二、扫描文件夹下所有文件
  • 三、扫描文件夹下所有文件,排除指定文件夹
  • 四、扫描文件夹下指定类型文件
  • 五、扫描文件夹下指定类型文件,排除指定文件夹
  • 六、在指定文件中搜索字符串
  • 七、在文件夹下指定类型的文件中搜索字符串
  • 八、在文件夹下指定类型的文件中搜索字符串,排除指定文件夹
  • 九、在指定文件夹下的所有可读文件中搜索字符串
  • 十、在指定文件夹下的所有可读文件中搜索字符串,排除指定文件夹
  • 十、打成jar包使用

一、工具类

import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.*;public class SearchWord {//当要在文件中搜索内容时,遇到以下非文本文件跳过public static List<String> excludeFileType = Arrays.asList("jar", "zip", "rar", "7z", "tar", "gz", "xz", "bz2", "doc","xls", "ppt", "pdf", "docx", "xlsx", "pptx", "jpg", "jpge", "gif", "png", "xltd","war","hprof","tiff", "svg", "psd", "mp3", "aac", "mp4", "avi", "flv", "mkv", "mkv", "mpeg", "msi","tgz","rmvb","mov", "wav", "raw", "dll", "ttf", "ttc", "fon", "iso", "isz", "esd", "wim", "gho", "dmg", "mpf", "exe");/*** 搜索指定文件中的关键字** @param filePath  要搜索的文件路径* @param searchStr 要搜索的关键字* @return 返回的 map<行数, 该行内容>*/public static Map<Integer, String> scanFile(String filePath, String searchStr) {Map<Integer, String> map = new LinkedHashMap<>();FileInputStream file = null; //读取文件为字节流try {file = new FileInputStream(filePath);InputStreamReader in = new InputStreamReader(file, StandardCharsets.UTF_8); //字节流转化为字符流,以GBK读取防止中文乱码BufferedReader buf = new BufferedReader(in); //加入到缓存区String str = "";int row = 1;while ((str = buf.readLine()) != null) { //按行读取,到达最后一行返回nullif (str.contains(searchStr)) {map.put(row, str);}row++;}buf.close();file.close();} catch (FileNotFoundException e) {e.printStackTrace();} catch (IOException e) {e.printStackTrace();}return map;}/*** 扫描dirPath下所有文件** @param dirPath 要搜索的文件夹路径* @return 返回所有文件的路径*/public static List<String> getAllFilesPath(String dirPath) {List<String> list = new ArrayList<>();return getAll_FilesPath(dirPath, list);}/*** 扫描dirPath下所有文件** @param dirPath    要搜索的文件夹路径* @param excludeDir 不扫描的文件夹名列表* @return 返回所有文件的路径*/public static List<String> getAllFilesPathEx(String dirPath, List<String> excludeDir) {List<String> list = new ArrayList<>();return getAll_FilesPath(dirPath, list, excludeDir);}/*** 扫描dirPath下的所有文件类型是fileType的文件** @param dirPath  要搜索的文件夹路径* @param fileType 文件后缀,要扫描的文件的类型* @return 返回所有fileType类型文件的路径*/public static List<String> getAllFilesPath(String dirPath, List<String> fileType) {List<String> list = new ArrayList<>();return getAllFiles(dirPath, fileType, list);}/*** 扫描dirPath下的所有文件类型是fileType的文件** @param dirPath    要搜索的文件夹路径* @param fileType   文件后缀,要扫描的文件的类型* @param excludeDir 不扫描的文件夹名列表* @return 返回所有fileType类型文件的路径*/public static List<String> getAllFilesPath(String dirPath, List<String> fileType, List<String> excludeDir) {List<String> list = new ArrayList<>();return getAllFiles(dirPath, fileType, list, excludeDir);}/*** @param dirPath   要搜索的文件夹路径* @param searchStr 要搜索的关键字* @param fileType  要搜索的文件后缀* @return <文件名, <行数, 该行内容>>*/public static Map<String, Map<Integer, String>> searchFiles(String dirPath, String searchStr, List<String> fileType) {return searchFiles(dirPath, searchStr, fileType, null);}/*** @param dirPath    要搜索的文件夹路径* @param searchStr  要搜索的关键字* @param fileType   要搜索的文件后缀* @param excludeDir 不扫描的文件夹名列表* @return <文件名, <行数, 该行内容>>*/public static Map<String, Map<Integer, String>> searchFiles(String dirPath, String searchStr, List<String> fileType, List<String> excludeDir) {List<String> allFiles = excludeDir == null || excludeDir.size() == 0 ? getAllFilesPath(dirPath, fileType) : getAllFilesPath(dirPath, fileType, excludeDir);Map<String, Map<Integer, String>> searchInfo = new LinkedHashMap<>();for (String f : allFiles) {System.out.println("正在文件中搜索,当前搜索文件:" + f);Map<Integer, String> map = scanFile(f, searchStr);if (map.size() != 0) {searchInfo.put(f, map);}}return searchInfo;}/*** 搜索文件夹下所有可读文件中是否含有要查找的关键字** @param dirPath   要搜索的文件夹路径* @param searchStr 要搜索的关键字* @return <文件名, <行数, 该行内容>>*/public static Map<String, Map<Integer, String>> searchAllFiles(String dirPath, String searchStr) {return searchAllFiles(dirPath, searchStr, null);}/*** 搜索文件夹下所有可读文件中是否含有要查找的关键字** @param dirPath    要搜索的文件夹路径* @param searchStr  要搜索的关键字* @param excludeDir 不扫描的文件夹名列表* @return <文件名, <行数, 该行内容>>*/public static Map<String, Map<Integer, String>> searchAllFiles(String dirPath, String searchStr, List<String> excludeDir) {List<String> allFiles = excludeDir == null || excludeDir.size() == 0 ? getAllReadFilessPath(dirPath, new ArrayList<>(), null) : getAllReadFilessPath(dirPath, new ArrayList<>(), excludeDir);Map<String, Map<Integer, String>> searchInfo = new LinkedHashMap<>();for (String f : allFiles) {System.out.println("正在文件中搜索,当前搜索文件:" + f);Map<Integer, String> map = scanFile(f, searchStr);if (map.size() != 0) {searchInfo.put(f, map);}}return searchInfo;}/*** @param dirPath   要搜索的文件夹路径* @param searchStr 要搜索的关键字* @param fileType  要搜索的文件后缀* @return <文件名, <行数, 该行内容>>*/public static void searchAndPrint(String dirPath, String searchStr, List<String> fileType) {Map<String, Map<Integer, String>> map = SearchWord.searchFiles(dirPath, searchStr, fileType);for (Map.Entry<String, Map<Integer, String>> m : map.entrySet()) {System.out.println("文件路径: " + m.getKey());for (Map.Entry<Integer, String> n : m.getValue().entrySet()) {System.out.println("第" + n.getKey() + "行:" + n.getValue());}System.out.println();}}//获取所有的文件路径,excludeDir是要跳过查询的文件夹名列表public static List<String> getAllReadFilessPath(String dirPath, List<String> list, List<String> excludeDir) {File file = new File(dirPath);File[] tempList = file.listFiles();System.out.println("正在扫描文件夹:" + dirPath);if (null != tempList) {for (int i = 0; i < tempList.length; i++) {String filePath = tempList[i].toString();String file_Type = filePath.substring(filePath.lastIndexOf(".") + 1);if (tempList[i].isFile()) {//如果是可读的文本文件if (!excludeFileType.contains(file_Type)) {list.add(filePath);}} else {if (excludeDir == null || excludeDir.size() == 0) {getAllReadFilessPath(filePath, list, excludeDir);} else {String dirName = filePath.substring(filePath.lastIndexOf(File.separator) + 1);if (!excludeDir.contains(dirName)) {//如果是文件夹则递归getAllReadFilessPath(filePath, list, excludeDir);}}}}}return list;}//获取文件夹下所有的文件路径,excludeDir是要跳过查询的文件夹名列表public static List<String> getAll_FilesPath(String dirPath, List<String> list, List<String> excludeDir) {File file = new File(dirPath);File[] tempList = file.listFiles();System.out.println("正在扫描文件夹:" + dirPath);if (null != tempList) {for (int i = 0; i < tempList.length; i++) {String filePath = tempList[i].toString();if (tempList[i].isFile()) {list.add(filePath);} else {//如果是文件夹则递归if (excludeDir == null || excludeDir.size() == 0) {getAll_FilesPath(filePath, list);} else {String dirName = filePath.substring(filePath.lastIndexOf(File.separator) + 1);if (!excludeDir.contains(dirName)) {//如果是文件夹则递归getAll_FilesPath(filePath, list, excludeDir);}}}}}return list;}//获取文件夹下所有的文件路径public static List<String> getAll_FilesPath(String path, List<String> list) {return getAll_FilesPath(path, list, null);}//获取所有的文件路径,fileType是所有要查询的文件类型public static List<String> getAllFiles(String dirPath, List<String> fileType, List<String> list) {return getAllFiles(dirPath, fileType, list, null);}//获取所有的文件路径,fileType是所有要查询的文件类型,excludeDir是要跳过查询的文件夹名列表public static List<String> getAllFiles(String dirPath, List<String> fileType, List<String> list, List<String> excludeDir) {File file = new File(dirPath);File[] tempList = file.listFiles();System.out.println("正在扫描文件夹:" + dirPath);if (null != tempList) {for (int i = 0; i < tempList.length; i++) {String filePath = tempList[i].toString();String file_Type = filePath.substring(filePath.lastIndexOf(".") + 1);if (tempList[i].isFile()) {//如果是文件if (fileType.contains(file_Type)) {list.add(filePath);}} else {if (excludeDir == null || excludeDir.size() == 0) {getAllFiles(filePath, fileType, list);} else {String dirName = filePath.substring(filePath.lastIndexOf(File.separator) + 1);if (!excludeDir.contains(dirName)) {//如果是文件夹则递归getAllFiles(filePath, fileType, list, excludeDir);}}}}}return list;}
}

二、扫描文件夹下所有文件

​ 扫描D:\迅雷下载\文件夹下的所有文件

    public static void main(String[] args) {String dir = "D:\\迅雷下载\\";List<String> filesPath = SearchWord.getAllFilesPath(dir);filesPath.forEach(System.out::println);}

输出:

D:\迅雷下载\1623720138.rar
D:\迅雷下载\codeNotes-master.zip
D:\迅雷下载\DittoSetup_64bit_3_24_184_0.exe
D:\迅雷下载\eclipse-inst-jre-win64.exe
D:\迅雷下载\eclipse-jee-2021-09-R-win32-x86_64.zip
D:\迅雷下载\fastjson-1.2.76.jar
D:\迅雷下载\guava-30.1.1-jre.jar
D:\迅雷下载\ideaIU-213.5605.12.exe
D:\迅雷下载\imageglass_8.2.6.6_x64.msi
D:\迅雷下载\latest-win64.zip.xltd
D:\迅雷下载\latest-win64.zip.xltd.cfg
D:\迅雷下载\layDate-v5.3.1\laydate\laydate.js
D:\迅雷下载\layDate-v5.3.1\laydate\theme\default\font\iconfont.woff
D:\迅雷下载\layDate-v5.3.1\laydate\theme\default\laydate.css
D:\迅雷下载\layDate-v5.3.1\test.html
D:\迅雷下载\layDate-v5.3.1\文档\文档.url
D:\迅雷下载\layDate-v5.3.1\更新日志.url
D:\迅雷下载\layDate-v5.3.1.zip
D:\迅雷下载\springboot-demo-maven-master.zip
D:\迅雷下载\yx12345sqlyog.rar
D:\迅雷下载\新建文件夹\ideaIU-2021.1.1.exe
D:\迅雷下载\新建文件夹\note.txt

三、扫描文件夹下所有文件,排除指定文件夹

扫描D:\迅雷下载\文件夹下的所有文件,不扫描"layDate-v5.3.1"文件夹下的文件

    public static void main(String[] args) {String dir = "D:\\迅雷下载\\";List<String> excludeDir = Arrays.asList("layDate-v5.3.1");List<String> filesPath = SearchWord.getAllFilesPathEx(dir,excludeDir);filesPath.forEach(System.out::println);}

输出:

D:\迅雷下载\1623720138.rar
D:\迅雷下载\codeNotes-master.zip
D:\迅雷下载\DittoSetup_64bit_3_24_184_0.exe
D:\迅雷下载\eclipse-inst-jre-win64.exe
D:\迅雷下载\eclipse-jee-2021-09-R-win32-x86_64.zip
D:\迅雷下载\fastjson-1.2.76.jar
D:\迅雷下载\guava-30.1.1-jre.jar
D:\迅雷下载\ideaIU-213.5605.12.exe
D:\迅雷下载\imageglass_8.2.6.6_x64.msi
D:\迅雷下载\latest-win64.zip.xltd
D:\迅雷下载\latest-win64.zip.xltd.cfg
D:\迅雷下载\layDate-v5.3.1.zip
D:\迅雷下载\springboot-demo-maven-master.zip
D:\迅雷下载\yx12345sqlyog.rar
D:\迅雷下载\新建文件夹\ideaIU-2021.1.1.exe
D:\迅雷下载\新建文件夹\note.txt

四、扫描文件夹下指定类型文件

​ 扫描D:\迅雷下载\文件夹下是jar、zip、txt类型的文件

    public static void main(String[] args) {        String dir = "D:\\迅雷下载\\";List<String> filesType = Arrays.asList("jar","zip","txt");List<String> filesPath = SearchWord.getAllFilesPath(dir,filesType);filesPath.forEach(System.out::println);}

输出:

D:\迅雷下载\codeNotes-master.zip
D:\迅雷下载\eclipse-jee-2021-09-R-win32-x86_64.zip
D:\迅雷下载\fastjson-1.2.76.jar
D:\迅雷下载\guava-30.1.1-jre.jar
D:\迅雷下载\layDate-v5.3.1.zip
D:\迅雷下载\springboot-demo-maven-master.zip
D:\迅雷下载\新建文件夹\note.txt

五、扫描文件夹下指定类型文件,排除指定文件夹

扫描D:\迅雷下载\文件夹下是jar、zip、txt类型的文件,如果有文件夹名是 "新建文件夹"的则不扫描该文件夹下文件

    public static void main(String[] args) {        String dir = "D:\\迅雷下载\\";List<String> filesType = Arrays.asList("jar","zip","txt");List<String> excludeDir = Arrays.asList("新建文件夹");List<String> filesPath = SearchWord.getAllFilesPath(dir,filesType,excludeDir);filesPath.forEach(System.out::println);}

输出:

D:\迅雷下载\codeNotes-master.zip
D:\迅雷下载\eclipse-jee-2021-09-R-win32-x86_64.zip
D:\迅雷下载\fastjson-1.2.76.jar
D:\迅雷下载\guava-30.1.1-jre.jar
D:\迅雷下载\layDate-v5.3.1.zip
D:\迅雷下载\springboot-demo-maven-master.zip

六、在指定文件中搜索字符串

​ 在server.log文件中搜索insertData关键字

    public static void main(String[] args) {        String filePath = "D:\\迅雷下载\\server.log";String searchWord = "insertData";Map<Integer, String> map = SearchWord.scanFile(filePath,searchWord);for(Map.Entry<Integer, String> entry : map.entrySet()){System.out.println("第"+entry.getKey()+"行:"+entry.getValue());}}

输出:

第67行:[http-nio-8080-exec-339  2021 Dec 27 15:10:42]insertData-开始插入数据库list大小:3
第68行:[http-nio-8080-exec-339  2021 Dec 27 15:10:42]insertData-nowadays:2021-12-27 15:10:42
第69行:[http-nio-8080-exec-339  2021 Dec 27 15:10:42]insertData-handleResult结束
第70行:[http-nio-8080-exec-339  2021 Dec 27 15:10:42]insertData-firm大小:15

七、在文件夹下指定类型的文件中搜索字符串

在 D:\迅雷下载\ 下所有"txt", "log"类型的文件中查找关键字insertData

    public static void main(String[] args) {   String dir = "D:\\迅雷下载\\";String searchStr = "insertData";List<String> fileType = Arrays.asList("txt", "log");Map<String, Map<Integer, String>> map = SearchWord.searchFiles(dir, searchStr, fileType);for (Map.Entry<String, Map<Integer, String>> m : map.entrySet()) {System.out.println("文件路径: " + m.getKey());for (Map.Entry<Integer, String> n : m.getValue().entrySet()) {System.out.println("第" + n.getKey() + "行:" + n.getValue());}System.out.println();}}

或者

    public static void main(String[] args) {   SearchWord.searchAndPrint(dir,searchStr,fileType);}

输出:

文件路径: D:\迅雷下载\server.log
第67行:[http-nio-8080-exec-339  2021 Dec 27 15:10:42]insertData-开始插入数据库list大小:3
第68行:[http-nio-8080-exec-339  2021 Dec 27 15:10:42]insertData-nowadays:2021-12-27 15:10:42
第69行:[http-nio-8080-exec-339  2021 Dec 27 15:10:42]insertData-handleResult结束
第70行:[http-nio-8080-exec-339  2021 Dec 27 15:10:42]insertData-firm大小:15文件路径: D:\迅雷下载\新建文件夹\note.txt
第15行:insertData-插入数据库
第17行:insertData-fserviceid:21-14
第19行:insertData-firmpv:1
第20行:insertData-firmuv:1
第21行:insertData-userpv:1
第22行:insertData-useruv:1

八、在文件夹下指定类型的文件中搜索字符串,排除指定文件夹

在 D:\迅雷下载\ 文件夹下所有"txt", "log"类型的文件中查找关键字insertData,如果文件夹名为 “新建文件夹” 则排除该文件夹的搜索

    public static void main(String[] args) {   String dir = "D:\\迅雷下载\\";String searchStr = "insertData";List<String> fileType = Arrays.asList("txt", "log");List<String> excludeDir = Arrays.asList("新建文件夹"); //遇到文件夹名为"新建文件夹"则跳过该文件夹Map<String, Map<Integer, String>> map = SearchWord.searchFiles(dir, searchStr, fileType, excludeDir);for (Map.Entry<String, Map<Integer, String>> m : map.entrySet()) {System.out.println("文件路径: " + m.getKey());for (Map.Entry<Integer, String> n : m.getValue().entrySet()) {System.out.println("第" + n.getKey() + "行:" + n.getValue());}System.out.println();}}

输出:

文件路径: D:\迅雷下载\server.log
第67行:[http-nio-8080-exec-339  2021 Dec 27 15:10:42]insertData-开始插入数据库list大小:3
第68行:[http-nio-8080-exec-339  2021 Dec 27 15:10:42]insertData-nowadays:2021-12-27 15:10:42
第69行:[http-nio-8080-exec-339  2021 Dec 27 15:10:42]insertData-handleResult结束
第70行:[http-nio-8080-exec-339  2021 Dec 27 15:10:42]insertData-firm大小:15

九、在指定文件夹下的所有可读文件中搜索字符串

在 D:\迅雷下载\ 文件夹下所有文本文件中查找关键字 ssssss,默认不会搜索音乐、视频等非文本文件

    public static void main(String[] args) throws IOException {String dir = "D:\\迅雷下载\\";String searchStr ="ssssss";Map<String, Map<Integer, String>> map = SearchWord.searchAllFiles(dir, searchStr);System.out.println("");System.out.println("--------------------------------------------------------");System.out.println("搜索完成,结果:");for (Map.Entry<String, Map<Integer, String>> m : map.entrySet()) {System.out.println("文件路径: " + m.getKey());for (Map.Entry<Integer, String> n : m.getValue().entrySet()) {System.out.println("第" + n.getKey() + "行:" + n.getValue());}System.out.println();}}

输出:

正在扫描文件夹:D:\迅雷下载\
正在扫描文件夹:D:\迅雷下载\layDate-v5.3.1
正在扫描文件夹:D:\迅雷下载\layDate-v5.3.1\laydate
正在扫描文件夹:D:\迅雷下载\layDate-v5.3.1\laydate\theme
正在扫描文件夹:D:\迅雷下载\layDate-v5.3.1\laydate\theme\default
正在扫描文件夹:D:\迅雷下载\layDate-v5.3.1\laydate\theme\default\font
正在扫描文件夹:D:\迅雷下载\layDate-v5.3.1\文档
正在扫描文件夹:D:\迅雷下载\test
正在扫描文件夹:D:\迅雷下载\新建文件夹
正在文件中搜索,当前搜索文件:D:\迅雷下载\aaa
正在文件中搜索,当前搜索文件:D:\迅雷下载\layDate-v5.3.1\laydate\theme\default\font\iconfont.eot
正在文件中搜索,当前搜索文件:D:\迅雷下载\layDate-v5.3.1\laydate\theme\default\font\iconfont.woff
正在文件中搜索,当前搜索文件:D:\迅雷下载\layDate-v5.3.1\laydate\theme\default\laydate.css
正在文件中搜索,当前搜索文件:D:\迅雷下载\layDate-v5.3.1\test.html
正在文件中搜索,当前搜索文件:D:\迅雷下载\layDate-v5.3.1\文档\官网.url--------------------------------------------------------
搜索完成,结果:
文件路径: D:\迅雷下载\aaa
第1行:ssssss

十、在指定文件夹下的所有可读文件中搜索字符串,排除指定文件夹

在 D:\迅雷下载\ 文件夹下排查指定文件夹,然后在所有文本文件中查找关键字 ssssss,默认不会搜索音乐、视频等非文本文件

    public static void main(String[] args) throws IOException {String dir = "D:\\迅雷下载\\";String searchStr ="ssssss";List<String> excludeDir = Arrays.asList("laydate"); //遇到文件夹名为"新建文件夹"则跳过该文件夹Map<String, Map<Integer, String>> map = SearchWord.searchAllFiles(dir, searchStr,excludeDir);System.out.println("");System.out.println("--------------------------------------------------------");System.out.println("搜索完成,结果:");for (Map.Entry<String, Map<Integer, String>> m : map.entrySet()) {System.out.println("文件路径: " + m.getKey());for (Map.Entry<Integer, String> n : m.getValue().entrySet()) {System.out.println("第" + n.getKey() + "行:" + n.getValue());}System.out.println();}}

输出:

正在扫描文件夹:D:\迅雷下载\
正在扫描文件夹:D:\迅雷下载\layDate-v5.3.1
正在扫描文件夹:D:\迅雷下载\layDate-v5.3.1\文档
正在扫描文件夹:D:\迅雷下载\test
正在扫描文件夹:D:\迅雷下载\新建文件夹
正在文件中搜索,当前搜索文件:D:\迅雷下载\aaa
正在文件中搜索,当前搜索文件:D:\迅雷下载\layDate-v5.3.1\laydate\theme\default\font\iconfont.eot
正在文件中搜索,当前搜索文件:D:\迅雷下载\layDate-v5.3.1\laydate\theme\default\font\iconfont.woff
正在文件中搜索,当前搜索文件:D:\迅雷下载\layDate-v5.3.1\laydate\theme\default\laydate.css
正在文件中搜索,当前搜索文件:D:\迅雷下载\layDate-v5.3.1\test.html
正在文件中搜索,当前搜索文件:D:\迅雷下载\layDate-v5.3.1\文档\官网.url--------------------------------------------------------
搜索完成,结果:
文件路径: D:\迅雷下载\aaa
第1行:ssssss

十、打成jar包使用

    public static void main(String[] args) throws IOException {List<String> excludeDir = Arrays.asList("laydate"); //遇到文件夹名为"新建文件夹"则跳过该文件夹String dir = ""; //要扫描的文件夹String searchStr = ""; //要查找的字符串String[] array = null; //不查找的文件夹名for (int i = 0; i < args.length; i++) {if (i == 0) {dir = args[i];}else if (i == 1) {searchStr = args[i];}else if (i == 2) {String tempDirs = args[i];array = tempDirs.split(",");}System.out.println("参数" + (i + 1) + "的值为:" + args[i]);}Map<String, Map<Integer, String>> map = array == null ? SearchWord.searchAllFiles(dir, searchStr) : SearchWord.searchAllFiles(dir, searchStr, new ArrayList<>(Arrays.asList(array)));System.out.println("");System.out.println("--------------------------------------------------------");System.out.println("搜索完成,结果:");for (Map.Entry<String, Map<Integer, String>> m : map.entrySet()) {System.out.println("文件路径: " + m.getKey());for (Map.Entry<Integer, String> n : m.getValue().entrySet()) {System.out.println("第" + n.getKey() + "行:" + n.getValue());}System.out.println();}}

打成jar包后可放到服务器使用,假设打成scan.jar,命令如下:

java -jar scan.jar param1 param2 param3

其中param1为要扫描的文件夹,param2为要查找的字符串,param3为不查找的文件夹名通过逗号隔开

如:
查找D:\myFiles\文件夹下的文件中搜索含有love字符串的位置,遇到文件夹名为move或music则跳过该文件夹

java -jar scan.jar D:\myFiles\ love move,music

java文件扫描及多文件中查找字符串相关推荐

  1. java文件中查找字符串_Java 在本地文件中查找固定字符串

    适用范围:只适用于在文本文档中查找(如,txt.java.c等等,并不适用与doc.xls等等这些文件),可嵌套文件夹.但是对中文不支持. 例如:文件夹:F:/demo 子文件夹:F:/demo/er ...

  2. 在目录下所有文件中查找字符串

    目录下的所有文件中查找字符串 find .| xargs grep -ri "class" 目录下的所有文件中查找字符串,并且只打印出含有该字符串的文件名 find .| xarg ...

  3. java 匹配最后一次出现的字符_在Java中查找字符串中字符的最后一次出现

    使用该lastIndexOf()方法在Java中查找字符串中字符的最后一次出现. 假设以下是我们的字符串.String myStr = "Amit Diwan"; 在上面的字符串中 ...

  4. java字符串字符排列组合_如何在Java中查找字符串的所有排列

    java字符串字符排列组合 In this tutorial, we will learn how to find the permutation of a String in a Java Prog ...

  5. c语言找字符串的位置,C语言开发中查找字符串位置的方法

    C语言开发中,我们可以使用strstr函数找到字符串,程序员在这个时候要怎么操作呢?别着急,今天是爱站技术频道小编为大家介绍的C语言开发中查找字符串位置的方法,一起参考看看吧! C语言strchr() ...

  6. hiho1482出勤记录II(string类字符串中查找字符串,库函数的应用)

    string类中有很多好用的函数,这里介绍在string类字符串中查找字符串的函数. string类字符串中查找字符串一般可以用: 1.s.find(s1)函数,从前往后查找与目标字符串匹配的第一个位 ...

  7. 在Python中查找字符串长度

    介绍 (Introduction) In this tutorial, we are going to discuss how we can find string length in Python. ...

  8. Java实现 LeetCode 609 在系统中查找重复文件(阅读理解+暴力大法)

    609. 在系统中查找重复文件 给定一个目录信息列表,包括目录路径,以及该目录中的所有包含内容的文件,您需要找到文件系统中的所有重复文件组的路径.一组重复的文件至少包括二个具有完全相同内容的文件. 输 ...

  9. python 查找指定文件_python实现在目录中查找指定文件的方法

    本文实例讲述了python实现在目录中查找指定文件的方法.分享给大家供大家参考.具体实现方法如下: 1. 模糊查找 代码如下: import os from glob import glob #用到了 ...

  10. linux下如何搜索某个文件,技术|如何在 Linux 中查找一个文件

    对于新手而言,在 Linux 中使用命令行可能会非常不方便.没有图形界面,很难在不同文件夹间浏览,找到需要的文件.本篇教程中,我会展示如何在 Linux 中查找特定的文件. 第一步要做的是find 命 ...

最新文章

  1. 橡皮筋进度条ElasticProgressBar
  2. python数字类型-详解python的数字类型变量与其方法
  3. Linux下系统函数open,read,write,lseek函数
  4. Eclipse 常用快捷键
  5. Shift and Reverse
  6. Java中的8种原始类型
  7. UITableView:改变 TableHeaderView 的高度
  8. 关于Java成员变量、局部变量、方法,在JVM的内存空间分配
  9. verilog学习(1)基本语法
  10. SQL Server Log Shipping学习总结
  11. nginx配置与常见错误解决方法
  12. 定义一个复数类Complex,重载运算符“+”,
  13. 四旋翼无人机的动力学模型
  14. 2021年中国MEMS话筒市场趋势报告、技术动态创新及2027年市场预测
  15. android支持wifi11ad,WiFi“千兆”必杀,802.11ax/802.11ad标准探秘
  16. 计算机教师的人生格言,教师人生格言大全
  17. python装饰图解_Python装饰器(Decorate)使用图解
  18. 用MATLAB沉降观测实验,观测沉降论文,关于建筑物沉降观测数据处理相关参考文献资料-免费论文范文...
  19. vue中获取后一页面,前一页面的url
  20. 微信内分享域名防红方案-微信域名防封跳转技术的方案解析_微信域名防封推广源码

热门文章

  1. 爬楼梯 java_爬楼梯问题java实现
  2. 5 个关键点!优化你的 UI 原型设计
  3. python图片尺寸大小修改_Python实现更改图片尺寸大小的方法(基于Pillow包)
  4. 2018年,数万款小程序暴毙在路上
  5. java茌首字母_汉字获取拼音首字母(1)
  6. 解决ps图层不能填充问题
  7. python识别验证码并自动登录_Python完全识别验证码自动登录实例详解
  8. 大数据发展的7个趋势
  9. Excel表中只能选择固定内容
  10. VueX浏览器刷新如何保存数据