Java: Import saved ArrayList and display in text field
having trouble with this.
I have an ArrayList which I have output t开发者_高级运维o a file, I want to be able to open this file and display the contents in a jTextField
private void btnSubmitActionPerformed(java.awt.event.ActionEvent evt) {
computer= new Computer();
computer.setComputerType(cbType.getSelectedItem().toString() +"\n");
computer.setWeight(txtWeight.getText() +"\n");
computer.setBatteryLife(txtBattery.getText() +"\n");
computer.setScreenSize(txtScreenSize.getText() +"\n");
computer.setRamSize(txtRAM.getText() +"\n");
computer.setOS(cbOS.getSelectedItem().toString() +"\n");
computer.setManufacturerName(txtManufacturer.getText() +"\n");
computer.setProcessorModel(txtCPU.getText() +"\n");
computer.setCpuCoreType(txtCPUCore.getText() +"\n");
//Store computer in ArrayList
myComputerList.add(computer);
System.out.print("Size of array " + myComputerList.size() + "\n");
System.out.print("\n");
}
private void btnSaveActionPerformed(java.awt.event.ActionEvent evt) {
try {
ObjectOutputStream outputStream = new ObjectOutputStream(
new FileOutputStream("ArrayFile.bin"));
outputStream.writeObject(myComputerList);
outputStream.close();
System.out.println("Array output file" + "\n");
}
catch(IOException err)
{
System.out.println("Problem with file output");
}
System.out.println("Computer written to the file computers.bin");
}
精彩评论