📅  最后修改于: 2022-03-11 15:04:36.255000             🧑  作者: Mango
import java.util.*;
import java.io.*;
public class Task1 {
public static void main(String[] args) throws Exception {
// Check number of arguments passed
if (args.length != 1) {
System.out.println("Usage: TextFile");
System.exit(0);
}
String filename = args[0];
TreeSettreeSet = new TreeSet();
try
{
Scanner in = new Scanner(new File(filename));
String line;
while ((line = in.nextLine())!=null)
{
String[] tokens = line.split("[||n|\t|\r|.|,|)|(|-|\"]");
for (int i = 0; i < tokens.length; i++)
//for (int i = tokens.length -1; i >= 0; i--)
treeSet.add(tokens[i]);
}
}
catch (Exception ex)
{
}
Iterator iterator = treeSet.iterator();
System.out.println("\nDisplay words in ascending order");
while (iterator.hasNext()) {
System.out.println(iterator.next());
}
}
}