Java code:
for (int i=0; i<13000; i++){
new FileReader("helloWorld.txt");
}
gives:
> Exception in thread "main" java.io.FileNotFoundException: helloWorld.txt (Too many open files)
at java.base/java.io.FileInputStream.open0(Native Method)
at java.base/java.io.FileInputStream.open(FileInputStream.java:219)
at java.base/java.io.FileInputStream.<init>(FileInputStream.java:157)
at java.base/java.io.FileInputStream.<init>(FileInputStream.java:112)
at java.base/java.io.FileReader.<init>(FileReader.java:60)
at Main.main(Main.java:14)
And it is pretty ok as there is not enough system resources. But I have no idea why this works:
for (int i=0; i<13000; i++){
new BufferedReader(new FileReader("helloWorld.txt"));
}
As even there are many differences between FileReader and BufferedReader, there is still: new FileReader("helloWorld.txt") - so shouldnt it get out of resources as in 1st case?