Here is an example code to read / write one character at a time
public class CopyCharacters {
public static void main(String[] args) throws IOException {
FileReader inputStream = null;
FileWriter outputStream = null;
try {
inputStream = new FileReader("xanadu.txt");
outputStream = new FileWriter("characteroutput.txt");
int c;
while ((c = inputStream.read()) != -1) {
outputStream.write(c);
}
} finally {
if (inputStream != null) {
inputStream.close();
}
if (outputStream != null) {
outputStream.close();
}
}
}
}
Note. This answer has been updated to copy the sample code from the Ref link, but I can see that this is essentially the same answer as given below.
ref:
http://download.oracle.com/javase/tutorial/essential/io/charstreams.html
user974465
source
share