There is a new method on Java SE 7 for prevent exhausting of Heap space of memory for Readline method on file reading operations. Its called Files.size() method, If the file is within the limit, we can assume that the standard readLine() method will not exhaust memory.
Example Usage:::::::::::
class ReadFile {
public static final int fileSizeLimit = 5000000;
public ReadFile(String filename) throws IOException {
if (Files.size(Paths.get(filename)) > fileSizeLimit) {
throw new IOException("File not compliant large");
}
this.input = new FileReader(filename);
this.reader = new BufferedReader(input);
}
//
No comments:
Post a Comment