RosettaCodeData/Task/Globally-replace-text-in-several-files/Java/globally-replace-text-in-several-files-1.java

17 lines
462 B
Java
Raw Permalink Normal View History

2015-02-20 00:35:01 -05:00
import java.io.*;
import java.nio.file.*;
2013-06-05 21:47:54 +00:00
2015-02-20 00:35:01 -05:00
public class GloballyReplaceText {
public static void main(String[] args) throws IOException {
for (String fn : new String[]{"test1.txt", "test2.txt"}) {
String s = new String(Files.readAllBytes(Paths.get(fn)));
s = s.replace("Goodbye London!", "Hello New York!");
try (FileWriter fw = new FileWriter(fn)) {
fw.write(s);
}
}
}
2013-06-05 21:47:54 +00:00
}