So if the contents of a text file is FCCCC, the output of the same text file should be fcccc.
I have written the following code
import java.lang.*;
import java.io.*;
import java.io.FileWriter;
import java.io.IOException;
class A
{
public static void main(String args[]) throws IOException
{
try
{
FileReader reader = new FileReader("doc1.txt");
FileWriter writer = new FileWriter("doc1.txt", true);
int character=' ';
char m;
while ((character = reader.read()) != -1)
{
m=Character.toLowerCase((char)character);
System.out.println(m);
writer.write(m);
}
reader.close();
writer.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
In the code above if the contents of the text file are FCCCC then the output is FCCCCfcccc.
What is the mistake in the code?