Witam, mam problem gdyż chce wyświetlić w TextArea tablice ArrayList<String> z pliku .tmp . Wszystko sie wyświetla tylko przy pierwszym wyświetleniu wystepuję "null". Tzn mając w pliku .tmp tablice ArrayList wyświetlając ją wynik to np: null1,2,3,4,5,6. Po ponownym wczytaniu pliku .tmp za pomoca Button. Zawartość .tmp wyświetla się prawidłowo.
Zapis
private ArrayList<String> namesArray = new ArrayList<String>();
...
...
...
public void writeNamesToFile() throws IOException{
FileOutputStream fos = new FileOutputStream("t.tmp");
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(namesArray);
oos.close();
}
Odczyt
public List<String> loadFileNames() throws IOException, ClassNotFoundException{
FileInputStream fis = new FileInputStream("t.tmp");
ObjectInputStream ois = new ObjectInputStream(fis);
List<String> names = (List<String>) ois.readObject();
ois.close();
return names;
}
public void getNames(List<String> nameList){
for(String x : nameList){
text+=x+"\n";
}
textArea.clear();
textArea.setText(text);
}
@FXML
void checkNameList() throws IOException, ClassNotFoundException {
getNames(loadFileNames());
}