Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8280865
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T09:50:10+00:00 2026-06-08T09:50:10+00:00

I’m supposed to create a program that displays an editable CSV in a spreadsheet

  • 0

I’m supposed to create a program that displays an editable CSV in a spreadsheet format, then pulls and appends information from an LDAP source into said spreadsheet and saves it. As it is a lot to handle right off the bat, I’m taking it in small chunks at a time.

Not even going to bother with the LDAP bits yet, I just want to get the Load > Edit > Save bits to work for now.

I figure that if I play around with opening, displaying, and saving .TXT files first I can easily transfer what I learn to later when I implement the .CSV portion. However, I am having difficulties making the Save portion work right (read: at all), and I got a bit of help from reading other posts on here, so I figured I’d ask.

Note: the Oracle Java tute for JFileChooser doesn’t cover saving except to barely touch on how to start implementing it, not how it actually functions.

a link to my code:
http://pastebin.com/tWnYrwgM

The code I need the most help with currently:

private void SaveActionPerformed(java.awt.event.ActionEvent evt) {                                    
//TODO
}

I don’t have anything in there currently because I never actually got anything to work when I Built, Ran, or Debugged the project when I did have code there.

I guess what I am trying to say is that I am having trouble writing to file.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T09:50:12+00:00Added an answer on June 8, 2026 at 9:50 am

    Okay, this would be a sample implementation of what you need to do.
    Be aware that while this works for basic situations it is not enough. Using an established CSV Library will do much better this is just for educational purpose.

    JTable myTable; 
    public void actionPerformed(ActionEvent e) {
        try {
            TableModel model = myTable.getModel(); // the table model contains all the data. Read its JavaDoc API it is enlightend when you work with JTables and you can do lots of neat stuff with it.
            JFileChooser fc = new JFileChooser();
            if(fc.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) { // no save when the user canceled.
                File target = fc.getSelectedFile();
                FileWriter fWri = new FileWriter(target); // this will create the file, but not any parent directories that might not exist. If there are parent directories that don't exist, this line will throw a FileNotFoundException.
                for(int ii = 0; ii < model.getRowCount(); ii++) {
                    StringBuilder lineValue = new StringBuilder();
                    for(int jj = 0; ii < model.getColumnCount(); jj++) {
                        lineValue.append(model.getValueAt(ii, jj));
                        lineValue.append(",");
                    }
                    lineValue.substring(0, lineValue.length() -1); // cut away the last ,
                    fWri.write(lineValue + "\r\n"); // the RFC suggests CRLF, but don't be surprised when you get a CSV from somewhere that has only LF or something. Its because of lines like this that you want a library handle it for you.
                }
                fWri.flush();// in fact, this and the next line should go to a 'finally' block. Read about correct and clean file writing to learn more.
                fWri.close();
            }
        } catch (IOException ioex) {
             // file not found, cant be written to, etc. You handle it here.
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a view passing on information from a database: def serve_article(request, id): served_article
I'm trying to create an if statement in PHP that prevents a single post
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.