...
This noncompliant code example tries to ensure that the file it opens contains exactly 1024 bytes.:
Code Block | ||||
---|---|---|---|---|
| ||||
static long goodSize = 1024; public void doSomethingWithFile(String filename) { long size = new File( filename).length(); if (size != goodSize) { System.out.println("File is wrong size!"); return; } try (BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream( filename)))) { // ... work with file } catch (IOException e) { // Handle error } } |
...