0

我在网上搜索,只找到打开每个文件并将正则表达式应用于内容的示例。有没有办法将正则表达式应用于文件夹中的所有文件?我会在 linux 上使用“grep”,但我需要编写一个可移植的代码。

4

1 回答 1

0

你想要这样的东西吗?

for(File file : directory.listFiles())
{
    if(file.isFile())
    {
        String name = file.getName();
        String newName = name.replaceAll("foo","bar");
        file.renameTo(newName);
    }
}
于 2012-04-16T19:22:01.967 回答