-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaZtask.java
More file actions
40 lines (33 loc) · 1.3 KB
/
aZtask.java
File metadata and controls
40 lines (33 loc) · 1.3 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
import java.io.*;
public class aZtask {
public static void main(String[] args) {
String fileName = "KLSadd.tex"; //specified file to convert
try {
FileReader inputFile =
new FileReader(fileName);
BufferedReader br = //buffers input from the file
new BufferedReader(inputFile);
PrintWriter outputFile = (new PrintWriter(new FileWriter("aZoutput.txt"))); //sets up the output file
int x;
Character readLetter;
while((x = br.read()) != -1) {
readLetter = Character.valueOf((char) x);
if (Character.isUpperCase(readLetter)) //if M, print m
outputFile.write(Character.toLowerCase(readLetter));
else outputFile.write(Character.toUpperCase(readLetter)); //vice versa
}
br.close();
outputFile.close(); //closes files!
}
catch(FileNotFoundException ex) {
System.out.println(
"Unable to open file '" +
fileName + "'");
}
catch(IOException ex) {
System.out.println(
"Error reading file '"
+ fileName + "'");
}
}
}