queria imprimir os nomes de um arquivo em ordem decrescente utilizando um treeset um iterator e o método compareto, porém não estou conseguindo utilizar o metodo compareto para fazer a comparação e nem o método getLinha para retornar cada linha lida do arquivo.
o código está logo em seguida:
import java.io.;
import java.util.;
public class Ordena {
private String line;
public Ordena(String nomeArq) {
this.line = nomeArq;
}
public String getLinha() throws IOException {
return line;
}
public boolean maisLinhas() {
if (line == null) {
return false;
} else {
System.out.println("funciona");
return true;
}
}
class Comparador implements Comparator {
public int compare(Object s1, Object s2) {
String l1 = (String) s1;
String l2 = (String) s2;
return l1.compareTo(l2);
}
}
public static void main(String[] args) throws IOException {
BufferedReader bf = new BufferedReader(new FileReader("c:/nomes.txt"));
Set<String> st = new TreeSet<String>();
while (bf.ready()) {
String s = bf.readLine();
st.add(s);
}
Iterator<String> it = st.iterator();
while (it.hasNext()) {
System.out.println(it.next());
}
bf.close();
}
}