2017-05-04 2 views
0

Je reçois une erreur de sortie quand je suis en train d'écrire le contenu de mon chaînée dans un fichier texteLinkedList écriture dans un fichier texte, mais la sortie est garbage

try { 
     FileOutputStream out = new FileOutputStream("ValidMovesMatrix.txt"); 
     ObjectOutputStream oout = new ObjectOutputStream(out); 
     oout.writeObject("--+ This will show all the VALID moves A* algorithm has taken to come up with the solution +---"); 
     oout.writeObject(" "); 
     for (int matrixIdx = 0; matrixIdx < matrixStack.size(); matrixIdx++) { 
      Object matrixShow = matrixStack.get(matrixIdx); 
      oout.writeObject(matrixShow); 
     } 
     oout.close(); 
    } catch (Exception ex) { 
     System.out.println("Output error"); 
    } 

Il n'a pas imprimer le contenu de mon chaînée et le fichier texte de sortie contenait les déchets suivants:

¬í t _--+ This will show all the VALID moves A* algorithm has taken to come up with the solution +---t {sr java.io.NotSerializableException(Vx ç†5 xr java.io.ObjectStreamExceptiondÃäk9ûß xr java.io.IOExceptionl€sde%ð« xr java.lang.ExceptionÐý>;Ä xr java.lang.ThrowableÕÆ5'9w¸Ë L causet Ljava/lang/Throwable;L 
detailMessaget Ljava/lang/String;[ 
stackTracet [Ljava/lang/StackTraceElement;L suppressedExceptionst Ljava/util/List;xpq ~ t MapStateur [Ljava.lang.StackTraceElement;F*<<ý"9 xp sr java.lang.StackTraceElementa Åš&6Ý… I 
lineNumberL declaringClassq ~ L fileNameq ~ L 
methodNameq ~ xpÿÿÿÿt java.io.ObjectOutputStreampt writeObject0sq ~ 
ÿÿÿÿq ~ pt writeObjectsq ~ 
    bt 
AlgoSolvert AlgoSolver.javat backtrackMovessq ~ 
    'q ~ q ~ t searchsq ~ 
    t 
ProjectOnet ProjectOne.javat 
acceptArgssq ~ 
    q ~ q ~ t mainsr &java.util.Collections$UnmodifiableListü%1µìŽ L listq ~ xr ,java.util.Collections$UnmodifiableCollectionB €Ë^÷ L ct Ljava/util/Collection;xpsr java.util.ArrayListxÒ™Ça I sizexp w xq ~ $x 
+1

vous devriez rendre la classe sérialisable ou mettre du code vous-même pour la rendre imprimable .. elle vide pratiquement sa mémoire. –

+0

comment je fais ça? – wazzza

Répondre

0

ObjectOutputStream objets à droite comme un format de code binaire sérialisé, qui peut être relue plus tard. Si vous voulez une sortie de texte, utilisez un PrintStream ou PrintWriter et implémentez Matrix.toString() pour écrire chaque matrice en tant que texte formaté.

+0

pouvez-vous me montrer les ficelles s'il vous plaît? – wazzza

+0

@wazzza vous pouvez lire l'explication 'toString()' dans [un autre QA sur la méthode 'toString()'] (http://stackoverflow.com/a/3615757/4648586). –