Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
    Bookmark Topic Watch Topic
  • New Topic

JCheckBox and File IO *Help*  RSS feed

Jessie Tan
Posts: 12
  • Mark post as helpful
  • send pies
  • Report post to moderator
i default a var, present="No"; then i wanna it to change to "Yes" when i checked the checkbox.. and then update to the text file...
but got reading file error...
Hope there's someone out there to help..
***Here's my code for the checkBox...***
public void itemStateChanged(ItemEvent e) {

JCheckBox checkCb = (JCheckBox)e.getSource();

Object item = e.getItem();

if (e.getStateChange() == ItemEvent.SELECTED) {
} else if (e.getStateChange() == ItemEvent.DESELECTED) {

public void actionPerformed (ActionEvent e) {

try {
catch (IOException ex) {
***Here's the update method for the textFile...***
public void mark() throws IOException {
Object rela = relation.getSelectedItem().toString();
String n = nameTf.getText();
String tel = telTf.getText();
String fam = famNoTf.getText();
String table = tableNoTf.getText();
String attend = present;

//create new object
GuestFile updatedGuest = new GuestFile(rela, n, tel, fam, table, attend);

//retrieve objects from text and store in ArrayList

boolean eof=false;
String inputStr="";
ArrayList gList=new ArrayList();
GuestFile gObject;
File inputFile = new File("GuestsData.txt");

FileInputStream in = new FileInputStream(inputFile);
InputStreamReader reader = new InputStreamReader(in);
BufferedReader fileInput = new BufferedReader(reader);

while (!eof) {
try {
if (inputStr==null)
else {
gObject=new GuestFile(inputStr,";");
} catch (EOFException e) {
} catch (IOException e) {
System.out.println("Error reading from file");
} catch (NoSuchElementException e) {
System.out.println("Error reading record:"+inputStr);

//overwrite object to be updated with the new Object
gList.set(index, updatedGuest);

//store ArrayList back into text

File outputFile = new File("GuestsData.txt");

if (outputFile.exists()) {

FileOutputStream out = new FileOutputStream(outputFile);
PrintStream fileOutput = new PrintStream(out);

for (int i=0; i<gList.size(); i++) {
gObject = (GuestFile)gList.get(i);
fileOutput.println(gObject.getRelationship() + ";" + gObject.getName() + ";" + gObject.getTel() + ";" + gObject.getFamNo() + ";" + gObject.getTableNo() + ";" + gObject.getPresent());


Gregg Bolinger
Ranch Hand
Posts: 15304
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Report post to moderator
Closing this duplicate post. Please respond to the thread in IO and Streams. Please do not cross post questions in multiple forums.
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!