Ora sono riuscito a togliere anche i punti con substring come hai suggerito tu.. Solo che ora che provo a far partire il file originale (con più di 5000 parole) il programma va in errore e precisamente mi esce fuori: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1
Qualcuno sa che come mai è uscito questo errore? Il codice del programma è il seguente:
codice:
public class traduttore {
public static void main(String[] args) throws FileNotFoundException, IOException {
int num=0;
int c=0;
int stringa;
FileReader file = new FileReader("dizionario.txt");
Scanner in = new Scanner(file);
while (in.hasNext()) {
String line = in.nextLine();
c=c+1;
if (c%2==0) {
String[] tokens= line.split("\\s");
stringa=tokens[1].length();
if (tokens[1].substring(stringa-1,stringa).equals("."))
{
System.out.println(tokens[1].substring(0,stringa-1));
}
else
{
System.out.println(tokens[1]);
}
}
else
{
System.out.println(line);
}
}
file.close();
}
}