Jak zaimplementowac obsulge tokenizerow do podzialu linii z tekstem na leksemy, aby w programie nizej podanym sortowane byly z pliku poszczegolne wyrazy a nie tylko same wiersze?
class Slownik {
static final int MaxLinijek = 128;
public static void main (String args[]) {
String tablicaSort[] = new String [MaxLinijek];
FileInputStream fs=null; FileOutputStream fw=null;
FileWriter fwrite=null;
StringBuffer strb = new StringBuffer();
String str="";
int nlines;
try {
fs = new FileInputStream ("C:\\Plik.txt");
fwrite = new FileWriter ("C:\\Slownik.txt");
} catch (Exception e) {
System.err.println ("Nie mozna otworzyc "+"C:\\slownik.txt");
System.exit (1);
}
BufferedReader ds = new BufferedReader(new InputStreamReader(fs));
for (nlines=0; nlines<MaxLinijek; nlines += 1) {
try {
tablicaSort[nlines] = ds.readLine();
if (tablicaSort[nlines] == null) break;
} catch (IOException e) {
System.err.println("Podczas odczytu pliku wystapil wyjatek."); break;
}
}
try {
fs.close ();//zamkniecie pliku
} catch (IOException e) {
System.err.println ("Podczas zamykania pliku wystapil wyjatek.");
}
System.out.println ("Nieposortowane wyrazenia:");
print (tablicaSort, nlines);
QSort qsort = new QSort ();
qsort.sort (tablicaSort, nlines);
System.out.println ("Posortowane wyrazenia:");
print (tablicaSort, nlines);
for(nlines=0; nlines<MaxLinijek; nlines++){
strb.append(tablicaSort[nlines]+"\r\n");}
str = strb.toString();
try {
fwrite.write(str);//zapisanie
fwrite.close();//zamkniecie
}catch(IOException e){};
}