import java.io.*;
public class ReadFile {
public static void read(File f) throws IOException {
//String delimiters = ".";
FileReader fr = new FileReader(f);
BufferedReader br = new BufferedReader(fr);
String line;
//int numberOfLines = 0;
while ((line = br.readLine()) != null) {
String[] tokens = line.split("\\.", 2);
String p1 = tokens[0];
String p2 = tokens[1];
System.out.println(p1);
System.out.println(p2);
//numberOfLines++;
}
//System.out.println("Numebr of lines in file: " + numberOfLines);
br.close();
fr.close();
}
public static void main(String[] args) {
File f = new File("F:\\Dictionary.txt");
try {
read(f);
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
J'ai un problème dans lequel j'utilise un dictionnaire comme un fichier texte et je veux lire les lignes (du fichier dictionnaire) puis diviser pour que je puisse stocker les "mots" et leurs "significations" dans différents index de tableau. Ce String[] tokens = line.split("\\.", 2); to read and split at only the first "." (so that words proceeding after "." will be splitted!). I seem to having an error of ArrayIndexOutOfBound and I don't know why. I want
Chaîne p1 = jetons [0]; pour stocker les mots et `String p12 = tokens 1; les significations des mots. Comment puis-je le faire? https://drive.google.com/open?id=0ByAbzVqaUg0BSFp5NXNHOGhuOFk Lien pour le dictionnaire.fichier de lecture (en utilisant FileReader) et la ligne de séparation en deux chaînes en Java