0

I want to write comma separated data in CSV file. Writing http request response in it.

Following is the code-

FileWriter fw = new FileWriter(Constants.LOGGING_FILE_PATH, true);
fw.write(currTime + ","+ responseBody);
fw.write(System.getProperty( "line.separator" ));
fw.flush();
fw.close();

Now problem is response is multiline, So when data is shown in Excel it messed up. I have attached screen shot. Can I have all data in one cell. Like ALT+ENTER.enter image description here

Dhrupal
  • 1,863
  • 1
  • 23
  • 38
  • Try this code : CSVWriter writer = null; try { writer = new CSVWriter(new FileWriter("/sdcard/myfile.csv"), ','); String[] entries = "first#second#third".split("#"); // array of your values writer.writeNext(entries); writer.close(); } catch (IOException e) { //error } – Mayur Patel Jul 29 '16 at 07:19
  • Watch this link : http://stackoverflow.com/questions/4632501/android-generate-csv-file-from-table-values – Mayur Patel Jul 29 '16 at 07:19
  • You can get list of data in one string and set it in the cell. Like : http://viralpatel.net/blogs/java-read-write-csv-file/ – Mayur Patel Jul 29 '16 at 07:23
  • mayurvpatel110, not working. Its saving data with hash. – Dhrupal Jul 29 '16 at 08:01
  • And I want to use FIleWriter without using CSV lib. – Dhrupal Jul 29 '16 at 08:03

0 Answers0