Чтение файла в TextArea - Java
Формулировка задачи:
Сделал модель чата,хочу что бы чат сохранялся в файл, а при открытии поднималась переписка, сохранять сохраняет читать не хочет вот код для чтения:
Вот код для отображения, хотя матюкается на чтение:
public TextArea aRead() throws IOException, ClassNotFoundException {
FileInputStream fis=new FileInputStream(filename);
//чтение из файла
ObjectInputStream ois=new ObjectInputStream(fis);
textArea=(TextArea) ois.readObject();
return textArea;
} if(file.canRead()){
try {
SeeMessage=readWrite.aRead();
} catch (IOException e) { e.printStackTrace();
} catch (ClassNotFoundException e) { e.printStackTrace(); }}Решение задачи: «Чтение файла в TextArea»
textual
Листинг программы
try {
FileReader fileReader = new FileReader("Text.txt");
BufferedReader bufferedReader = new BufferedReader(fileReader);
String inputFile = "";
String textFieldReadable = bufferedReader.readLine();
while (textFieldReadable != null){
inputFile += textFieldReadable;
textFieldReadable = bufferedReader.readLine();
}
textaread.setText(inputFile);
} сatch (FileNotFoundException ex) {
System.out.println("Файл не существует!");
} catch (IOException ex) {
System.out.println("Ошибка в/в!");
}