forked from deepdalsania/tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReplaceWord.java
More file actions
39 lines (30 loc) · 871 Bytes
/
ReplaceWord.java
File metadata and controls
39 lines (30 loc) · 871 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package file;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
public class ReplaceWord {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
File f = new File("D:/DEEP/forth.txt");
//f.createNewFile();
FileWriter fw = new FileWriter(f);
fw.write("Word1 is Word1");
System.out.println("Before Replacing : "+" Word1 is Word1");
fw.close();
FileReader fr = new FileReader(f);
BufferedReader br = new BufferedReader(fr);
String s = br.readLine();
System.out.println("After Replacing : " + s.replaceAll("Word1", "Word2"));
br.close();
fr.close();
FileWriter fw1 = new FileWriter(f);
fw1.write(s.replaceAll("Word1", "Word2"));
fw1.close();
}
}