-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfileReplace.java
More file actions
45 lines (32 loc) · 1.07 KB
/
fileReplace.java
File metadata and controls
45 lines (32 loc) · 1.07 KB
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
40
41
42
43
44
45
import java.io.*;
public class fileReplace
{
static void modifyFile(String file, String old, String newstr)
{
File modfile= new File(file);
String oldone = "";
BufferedReader reader = null;
FileWriter writer = null;
try
{
reader = new BufferedReader(new FileReader(modfile));
String line = reader.readLine();
while (line != null)
{
old = old + line + System.lineSeparator();
line = reader.readLine();
}
String newstr1 = old.replaceAll(old, newstr);
writer = new FileWriter(modfile);
writer.write(newstr1);
}
catch (IOException e)
{
e.printStackTrace();
}
}
public static void main(String[] args)
{
modifyFile("C://javaprograms//idk.txt", "old", "new");
}
}