Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我在网上搜索,只找到打开每个文件并将正则表达式应用于内容的示例。有没有办法将正则表达式应用于文件夹中的所有文件?我会在 linux 上使用“grep”,但我需要编写一个可移植的代码。
你想要这样的东西吗?
for(File file : directory.listFiles()) { if(file.isFile()) { String name = file.getName(); String newName = name.replaceAll("foo","bar"); file.renameTo(newName); } }