Streams not closed on exception
Review this Java method that copies log files.
What a strong answer looks like
Separate real bugs from style. Rank issues by severity, point at the root cause rather than the symptom, and suggest a concrete fix, specific and kind.
0:00 of about 18 min
Mark a line and say what kind of problem it is.0 findings
1public void archiveLogs(List<File> logs, File destDir) throws IOException {
2 for (File log : logs) {
3 FileInputStream in = new FileInputStream(log);
4 File out = new File(destDir, log.getName() + ".bak");
5 FileOutputStream os = new FileOutputStream(out);
6 byte[] buf = new byte[8192];
7 int n;
8 while ((n = in.read(buf)) != -1) {
9 os.write(buf, 0, n);
10 }
11 os.close();
12 in.close();
13 }
14}
Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.
Run or narrate your approach, then ask the coach.