#save, update, refresh jTable to my text file

1 messages · Page 1 of 1 (latest)

marsh karma
#

How to Update my save data and when i click refresh it duplicates how to stop the duplication?

indigo troutBOT
#

<@&987246399047479336> please have a look, thanks.

indigo troutBOT
#

While you are waiting for getting help, here are some tips to improve your experience:

Code is much easier to read if posted with syntax highlighting and proper formatting.

If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.

Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.

#

I uploaded your attachments as gist. That way, they are easier to read for everyone, especially mobile users 👍

marsh karma
#

this is my code for return and refresh

private void btnRefreshActionPerformed(java.awt.event.ActionEvent evt) {                                           
        String filePath = "C:\\Users\\Admin\\Documents\\zzzzz0\\DocFile.txt";
            File file = new File(filePath);
            
            try {
            FileReader fr = new FileReader(file);
            BufferedReader br = new BufferedReader(fr);
            
            DefaultTableModel model = (DefaultTableModel)jTable1.getModel();
            Object[] lines = br.lines().toArray();
            
            for(int i=0; i<lines.length; i++){
            String[] row = lines[i].toString().split(",");
            model.addRow(row);
            }
            
            } catch (FileNotFoundException ex) {
            Logger.getLogger(AdminLobby.class.getName()).log(Level.SEVERE, null, ex);
            }
    }

private void btnUpdateActionPerformed(java.awt.event.ActionEvent evt) {                                          
        
        String fName=txtDocFullName.getText();
        String dUser=txtDocUser.getText();
        String dPass=txtDocPass.getText();
        String filePath = "C:\\Users\\Admin\\Documents\\zzzzz0\\DocFile.txt";
            File file = new File(filePath);
            try {
            FileWriter fw = new FileWriter(file);
            fw.write(fName+","+dUser+","+dPass);
            //","+contactNo+
            fw.close();
            BufferedWriter bw = new BufferedWriter(fw);
            
            for(int i=0; i<jTable1.getRowCount();i++){
            for(int j=0; j<jTable1.getColumnCount();j++){
            bw.write(jTable1.getValueAt(i, j).toString());
            }
            bw.newLine();
            }
            
            bw.close();
            fw.close();
            
            } catch (IOException ex) {
            Logger.getLogger(AdminLobby.class.getName()).log(Level.SEVERE, null, ex);
            }
}
indigo troutBOT
# marsh karma this is my code for return and refresh ``` private void btnRefreshActionPerforme...

Detected code, here are some useful tools:

Formatted code
private void btnRefreshActionPerformed(java.awt.event.ActionEvent evt) {
  String filePath = "C:\\Users\\Admin\\Documents\\zzzzz0\\DocFile.txt";
  File file = new File(filePath);
  try {
    FileReader fr = new FileReader(file);
    BufferedReader br = new BufferedReader(fr);
    DefaultTableModel model = (DefaultTableModel) jTable1.getModel();
    Object[] lines = br.lines().toArray();
    for (int i = 0; i < lines.length; i++) {
      String[] row = lines[i] .toString().split(",");
      model.addRow(row);
    }
  } catch (FileNotFoundException ex) {
    Logger.getLogger(AdminLobby.class .getName()).log(Level.SEVERE, null , ex);
  }
}
private void btnUpdateActionPerformed(java.awt.event.ActionEvent evt) {
  String fName = txtDocFullName.getText();
  String dUser = txtDocUser.getText();
  String dPass = txtDocPass.getText();
  String filePath = "C:\\Users\\Admin\\Documents\\zzzzz0\\DocFile.txt";
  File file = new File(filePath);
  try {
    FileWriter fw = new FileWriter(file);
    fw.write(fName + "," + dUser + "," + dPass);
    //","+contactNo+
    fw.close();
    BufferedWriter bw = new BufferedWriter(fw);
    for (int i = 0; i < jTable1.getRowCount(); i++) {
      for (int j = 0; j < jTable1.getColumnCount(); j++) {
        bw.write(jTable1.getValueAt(i, j).toString());
      }
      bw.newLine();
    }
    bw.close();
    fw.close();
  } catch (IOException ex) {
    Logger.getLogger(AdminLobby.class .getName()).log(Level.SEVERE, null , ex);
  }
}
marsh karma
#

Update
i have only one problem left can anyone know how to update my table?
peepo_sad 🥹 cat_thumbs_up