-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEditFile.java
48 lines (40 loc) · 1.61 KB
/
EditFile.java
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
46
47
48
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
public class EditFile {
public static void main(String[] args) {
try{
//replace1 { with newline
/*
Path path = Paths.get("/Users/raveekhandagale/Documents/XML_and_WI/Data set/Douban/parsedRatings.txt");
Charset charset = StandardCharsets.UTF_8;
String content = new String(Files.readAllBytes(path), charset);
content = content.replaceAll("}", "\n");
Files.write(path, content.getBytes(charset));
*/
//replace1 ends here
//replace2 {user id: with "" and " " with "" and movie id: with "" and rating: with ""
Path path = Paths.get("/Users/raveekhandagale/Documents/XML_and_WI/Data set/Douban/parsedRatings.txt");
Charset charset = StandardCharsets.UTF_8;
String content = new String(Files.readAllBytes(path), charset);
content = content.replaceAll("userid:", "");
content = content.replaceAll(" ", "");
content = content.replaceAll("movieid:", "");
content = content.replaceAll("rating:", "");
content = content.replaceAll("\\{", "");
Files.write(path, content.getBytes(charset));
//replace 2 ends here
System.out.println("done");
}catch(IOException e){
e.printStackTrace();
}
}
}