-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmMtask.java
More file actions
42 lines (36 loc) · 1.48 KB
/
mMtask.java
File metadata and controls
42 lines (36 loc) · 1.48 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
import java.io.*;
public class mMtask {
public static void main(String[] args) {
String fileName = "KLSadd.tex"; //specified file to convert
try {
FileReader inputFile =
new FileReader(fileName);
BufferedReader br =
new BufferedReader(inputFile);
PrintWriter outputFile = (new PrintWriter(new FileWriter("mMoutput.txt"))); //output file setup
int x;
Character readLetter;
while((x = br.read()) != -1) { //reading character by character until the end of the stream has been reached (-1)
readLetter = Character.valueOf((char) x);
if ((readLetter == 'm') || (readLetter == 'M')) { //lowercase or uppercase conditionals
if (Character.isUpperCase(readLetter))
outputFile.write(Character.toLowerCase(readLetter));
else outputFile.write(Character.toUpperCase(readLetter));
}
else outputFile.write(readLetter);
}
br.close();
outputFile.close(); //closes both files
}
catch(FileNotFoundException ex) {
System.out.println(
"Unable to open file '" +
fileName + "'");
}
catch(IOException ex) {
System.out.println(
"Error reading file '"
+ fileName + "'");
}
}
}