This is my code:
try {
RandomAccessFile srcFile = new RandomAccessFile("src.txt", "rw");
} catch(FileNotFoundException e) {
e.printStackTrace();
}
This code gives me a warning that the RandomAccessFile
object srcFile is never closed.
But if I modify my code and declare the srcFile outside the try block (as in the code below), the warning goes away.
RandomAccessFile srcFile;
try {
srcFile = new RandomAccessFile("src.txt", "rw");
} catch(FileNotFoundException e) {
e.printStackTrace();
}
Why does this happen, since I'm not doing srcFile.close();
in any case?