Reputation: 1
How can I modfy this to work on Java 6?
Resource specification not allowed here for source level below 1.7
The type BufferedReader is not visible
public static void findFrequency() throws IOException {
try (BufferedReader ins = new BufferedReader(new FileReader("input.txt"))) {
int r;
while ((r = ins.read()) != -1) {
text=text+String.valueOf((char)r);
freq[r]++;
}
}
}
Upvotes: 0
Views: 1596
Reputation: 201467
To work with earlier versions of Java (without try-with-resources), make a small change...
BufferedReader ins = null;
try {
ins = new BufferedReader(new FileReader("input.txt"));
// As before...
} finally {
if (ins != null) {
try {
ins.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
Upvotes: 1