Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Write and Update CSV files

 
vardhan reddy
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
while writing CSV (reading data from excel file)I'm checking (CSV file) if file exist or not in specified directory. If exist I'm trying to update existing CSV (with new rows from excel) file. If not existing I'm creating new CSV file(this part working fine).
I'm blocked while updating CSV with new rows, Please check my code and let me know the way to complete this.
 
vardhan reddy
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First I'm creating 'temp' csv file and copying existing file data into temp file and adding new rows to temp file and rename temp file name with actual name.
Trying to delete existing csv file, but not working.
using

updated code:


Can any one tell me what is issue with delete function.
 
John Jai
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try closing the readers opened in below code just like you close your writer before calling the delete() method on the file object.

 
vardhan reddy
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks John, I missed that.
 
Rob Spoor
Sheriff
Pie
Posts: 20551
57
Chrome Eclipse IDE Java Windows
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you check our AccessingFileFormats FAQ entry you can find a few libraries that can do the hard work for you. I myself recommend opencsv.
 
vardhan reddy
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob, I will check opencsv.
when I run my current program getting below error.

 
Rob Spoor
Sheriff
Pie
Posts: 20551
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's probably an embedded object in there which JExcelAPI cannot handle.
 
vardhan reddy
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I use JExcelAPI for xlsx files getting error. Changed to apache poi XSSF, now I'm able to convert xlsx files into CSV format.
When I am trying to convert large (file size around 50,000 kb) file getting Exception in thread "main" java.lang.OutOfMemoryError: Java heap space. I have increased my heap size to 1024.
-Xmx1024M
 
Tim Moores
Bartender
Posts: 2851
46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
vardhan reddy wrote:If I use JExcelAPI for xlsx files getting error.

JExcelApi does not support XLSX, and it's unlikely that it ever will.
 
vardhan reddy
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
While testing with xlsx, came to know that.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic