I just started with I/O in java and please excuse me if my doubt is silly but i find it dificult to understand how this code works? variable c in code below is not incremented then the while loop will never terminate even if there is only one character in inputstream and outputstream will be filled with only one character continuously but this code actually works satisfactorily which i dont understand why?
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
public class CopyBytes {
public static void main(String[] args) throws IOException {
FileInputStream in = null;
FileOutputStream out = null;
try {
in = new FileInputStream("xanadu.txt");
out = new FileOutputStream("outagain.txt");
int c;
while ((c = in.read()) != -1) {
out.write(c);
}
} finally {
if (in != null) {
in.close();
}
if (out != null) {
out.close();
}
}
}
}