Click here to Skip to main content
13,797,987 members
Rate this:
 
Please Sign up or sign in to vote.
I have a project where I have used an Arduino ultrasonic sensor and have connected it to a java program which reads the values produced by the Arduino ultrasonic sensor via serial communication, the java program produces a real time chart plotting values that are being read from the Arduino.

I want to save that real time data into a csv file. The following code simply creates a file and stores it where the project is located on my computer and does contain any real time data:
{
            saveButton.setText("Save Data");
            String csvFile = "data.csv";
            File f = new File(csvFile);
            FileWriter writer = new FileWriter(csvFile);    
    }

What am I missing in order to as mentioned previously store the real time data into the csv file?

What I have tried:

Online website tutorials, YouTube video tutorials and example codes found online.
Posted 15-May-18 3:02am
Updated 15-May-18 3:44am
v2
Comments
Richard MacCutchan 15-May-18 9:56am
   
Data is data, you just need to write it to the file. However, creating a file as in the above code is not going to help because you create a new one each time through that block, but don't write anything to it. Open the file at the very beginning of your program then you can write to it any time.
Member 13710355 15-May-18 10:08am
   
First of all thank you for the advice but if you don't mind could you please elaborate on what you mean by " Open the file at the very beginning of your program then you can write to it any time" ?
Richard MacCutchan 15-May-18 10:37am
   
1. Start program
1.1. Open file(s) and other initialisation

2. Main loop
2.1. Collect data - if no more data go to 3.
2.2 Write stuff to the file
2.3 go to 2.1

3. Close file, release other resources, and exit

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web06 | 2.8.181207.3 | Last Updated 15 May 2018
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100