Am trying to create a .CSV file using float and string values in a single array. And use the array values to write .CSV file (I have many entries ex: > 50,000)
Ist String value...
long _time = (dataValue.getInt(0) & 0xffffffffL);
Date date = new Date(_time*1000L);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
String formattedDate = sdf.format(date); // 2015-07-03 09:48:41
IInd Float value...
float _resistanceValue = dataValue.getFloat(8); // 1.60774944E8
I need to join these two values dynamically {inside the while loop} in an array and using that value to write .CSV file
I have tried to join the values like...
ArrayList updateValue = new ArrayList();
updateValue.add(formattedDate,_resistanceValue);
//(Which I am not successful)
Using the below code to write .CSV file
private static final String FILE_HEADER = "Time,ResistanceValue";
private static final String NEW_LINE_SEPARATOR = "\n";
FileWriter fileWriter = null;
String fileName = "C:\\temp.csv";
FileWriter fileWriter = null;
try {
fileWriter = new FileWriter(fileName);
//Write the CSV file header
fileWriter.append(FILE_HEADER.toString());
//Add a new line separator after the header
fileWriter.append(NEW_LINE_SEPARATOR);
//Write a values of "formattedDate" & "_resistanceValue" into the CSV file
fileWriter.append(updateValue);
System.out.println("CSV file was created successfully !!!");
} catch (Exception e) {
System.out.println("Error in CsvFileWriter !!!");
e.printStackTrace();
} finally {
try {
fileWriter.flush();
fileWriter.close();
} catch (IOException e) {
System.out.println("Error while flushing/closing fileWriter !!!");
e.printStackTrace();
}
}
Please give me a direction to achieve it. Thanks