Write a program which reads a file and creates a file with the same contents of
ID: 3636290 • Letter: W
Question
Write a program which reads a file and creates a file with the same contents of all lower case letters. Keep in mind that other characters are not affected.
Create your own file to test your program. Your job is to set up the input and output files to have the program read from a file and write to a file.
Here is a basic program that will accomplish what is desired:
import java.io.*;
classInputOutput
{
public static void main(String args[])throws Exception
{
FileReaderfr = new FileReader("Exercise03.in");
FileWriterfw = new FileWriter("Exercise03.out");
int ch;
ch = fr.read();
while(ch != -1)
{
if((char)ch>='A' && (char)ch<='Z')
ch = ch +('a'-'A');
fw.write((char)ch);
ch = fr.read();
}
fr.close();
fw.close();
}
}
Explanation / Answer
import java.io.*;
public class InputOutput{
public static void main(String[] args) throws FileNotFoundException, IOException {
BufferedReader input = new BufferedReader(new FileReader("Exercise03.in"));
PrintWriter output = new PrintWriter(new FileWriter("Exercise03.out"));
String text = "";
while (input.ready()) {
text = input.readLine();
output.println(text.toLowerCase());
}
input.close();
output.close();
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.