This example comes from Sun's website, and I have absolutely no problems with it.
However, I do not comprehend why the compiler complains when the same source is used in a custom method and called from the main method, as follows:
I would appreciate it if someone could share the solution and point me in the direction of an explanation
Thanks,
--Glen
Memoria mihi benigna erit qui eam perscribam
Code:
import java.io.*;
public class Copy {
public static void main(String[] args) throws IOException {
File inputFile = new File("farrago.txt");
File outputFile = new File("outagain.txt");
FileReader in = new FileReader(inputFile);
FileWriter out = new FileWriter(outputFile);
int c;
while ((c = in.read()) != -1)
out.write(c);
in.close();
out.close();
}
}
However, I do not comprehend why the compiler complains when the same source is used in a custom method and called from the main method, as follows:
Code:
public class Copy {
public static void main(String[] args){
doCopy();
}
public static void doCopy() throws IOException {
File inputFile = new File("farrago.txt");
File outputFile = new File("outagain.txt");
FileReader in = new FileReader(inputFile);
FileWriter out = new FileWriter(outputFile);
int c;
while ((c = in.read()) != -1)
out.write(c);
in.close();
out.close();
}
}
I would appreciate it if someone could share the solution and point me in the direction of an explanation
Thanks,
--Glen
Memoria mihi benigna erit qui eam perscribam