-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheerror handling
More file actions
24 lines (22 loc) · 795 Bytes
/
eerror handling
File metadata and controls
24 lines (22 loc) · 795 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
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
public class RemoveComments {
public static void main(String[] args) {
String inputFile = "input.java";
String outputFile = "output.java";
try (BufferedReader reader = new BufferedReader(new FileReader(inputFile));
FileWriter writer = new FileWriter(outputFile)) {
String line;
while ((line = reader.readLine()) != null) {
line = line.replaceAll("//.*|/\\*.*?\\*/", "");
if (!line.trim().isEmpty()) {
writer.write(line + System.lineSeparator());
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
}