Is there a bug in this task because it seems like there's no filename as the first parameter in the main method...
package com.codegym.task.task36.task3605;
import java.io.*;
import java.util.NoSuchElementException;
import java.util.TreeSet;
/*
Using TreeSet
*/
public class Solution {
private static final String letters = "abcdefghijklmnopqrstuvwxyz";
public static void main(String[] args) throws IOException, ArrayIndexOutOfBoundsException {
TreeSet<Character> treeSet = new TreeSet<>();
String file1 = args[0];
File file = new File(file1);
BufferedReader in = new BufferedReader(new FileReader(file));
char[] buffer = new char[(int)file.length()];
in.read(buffer);
in.close();
for (char c : buffer){
if (letters.indexOf(Character.toLowerCase(c)) >= 0);
treeSet.add(Character.toLowerCase(c));
}
for (int i=0;i<5;i++){
try {
System.out.print(treeSet.first());
treeSet.remove(treeSet.first());
}
catch (NoSuchElementException ignored){
break;
}
}
}
}