howdy~
i did some exercises on file I/O, but weird that i can only read but not write. here is my code below:
import java.io.*;
class TestFile_001
{
public static void main(String[] args) throws Exception
{
copy();
}
public static void copy() throws IOException
{
File fIn = new File("TestFileStreamRead.txt");
File fOut = new File("TestFileStreamWrite.txt");
FileReader fr = new FileReader(fIn);
FileWriter fw = new FileWriter(fOut);
int n;
while(true)
{
n = fr.read();
if (n != -1)
{
fw.write(n);
}
else
{
break;
}
}
}
}
TestFileStreamWrite.txt is always empty after running the code, which is supposed to have same content as TestFileStreamRead.txt, i’m sticked here. any solution pls ?