Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File;
- import java.io.IOException;
- import org.apache.commons.io.FileUtils;
- public class Example {
- public static void main(String[] args) {
- File textFile = new File("Myself.txt");
- try {
- String data = FileUtils.readFileToString(textFile);
- data = data.replace("Khadija", "Saiyana");
- FileUtils.writeStringToFile(textFile, data);
- } catch (IOException e) {
- e.printStackTrace();
- }
- File myObj = new File("Myself.txt");
- if (myObj.delete()) {
- System.out.println("Deleted the file: " + myObj.getName());
- } else {
- System.out.println("Failed to delete the file.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement