besoin d'obtenir en quelque sorte ces deux fichiers txt pour servir de clé et de valeurs, j'ai eu le premier dans la liste de travail, mais j'ai besoin de tous les mots mappés à partir des deux fichiers txt .. je pense ce qui se passe est im ne pas analyser les fichiers correctement. Je suis capable de System.out.println (..) le contenu mais je reçois une valeur nulle pour les valeurs, donc il me manque quelque chose de grand ici. de toute façon nouveau programmeur ici c'est mon premier post. salut! =)hashmap et plusieurs fichiers txt java
import java.util.*;
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException {
//Create map structure **must have import
Map engJapDictionary = new HashMap<String,String>();
//user input
Scanner in = new Scanner(System.in);
System.out.print("Enter phrase for translation: ");
//name the user input
String name = in.next();
System.out.println("You wrote: " + name);
//Load Eng and Jap
String fileName = "word.txt";
String fileName1 = "word2.txt";
String line = null;
String line2= null;
try {
FileReader fileReader = new FileReader(fileName);
FileReader fileReader1 = new FileReader(fileName1);
BufferedReader bufferedReader = new BufferedReader(fileReader);
BufferedReader bufferedReader1 = new BufferedReader(fileReader1);
while ((line = bufferedReader.readLine()) != null) {
String parts[] = line.split("\t");
while ((line2 = bufferedReader1.readLine()) != null) {
String parts2[] = line2.split("\t");
engJapDictionary.put(parts[0], parts2[0]);
//for each entry in both txt files iterate through i think here. the .put works only for the first entry in both txt files.. =(
continue;
//System.out.println(engJapDictionary +"\n");
//System.out.println(line);
}
}
}catch (IOException e){}
//Size of the Dictionary!
System.out.println("The number of entries is: " + engJapDictionary.size());
// English to Japanese Dictionary
//Building dictionary the long way
engJapDictionary.put("me", "Watashi");
engJapDictionary.put("you", "anata");
engJapDictionary.put("hat", "boshi");
engJapDictionary.put("cat", "neko");
engJapDictionary.put("dream", "yume");
engJapDictionary.put("house", "uchi");
engJapDictionary.put("dog", "inu");
// System.out.println(engJapDictionary.get("you"));
// System.out.println(engJapDictionary.get("hat"));
// System.out.println(engJapDictionary.get("cat"));
// System.out.println(engJapDictionary.get("dream"));
// System.out.println(engJapDictionary.get("house"));
// System.out.println(engJapDictionary.get("dog"));
System.out.println("Japanese word: " + engJapDictionary.get(name));
System.out.println(engJapDictionary.get(name));
System.out.println(engJapDictionary.containsKey(name));
//Print the keys!!
//System.out.println("\n" + engJapDictionary.keySet());
//Print the values!!
//System.out.println(engJapDictionary.values());
}
}
Je parie que vous verrez l'erreur sans aucune aide si vous formatez votre code correctement. http://idownvotedbecau.se/noattempt/ – blafasel
ne pensais pas que je devais être flammé si tôt. =) je vois votre point cependant, le formatage est vraiment important .. contrôle k n'a pas semblé fonctionner pour moi en apportant mes trucs d'intellij. il est juste tout mucked .. –