java - Read CSV file and write back CSV File based on condition -



java - Read CSV file and write back CSV File based on condition -

i'm new java. i'm required read input data(csv)(large number of records) receive in given below format:

a,1 a,2 b,3 b,4 c,5 c,6 a,7 a,8 b,9 b,10 ...

i'm using printwriter write info new csv file. there a.ny way can write new csv file way above data? here status based on values a, b,c.

a,b,c 1,3,5 2,4,6 7,9 8,10...

i think possible if there a,b , c. thought can extended finite number of constants

what can like...

public void computenewcsv() { list<integer> = new linkedlist<integer>(); list<integer> b = new linkedlist<integer>(); list<integer> c = new linkedlist<integer>(); fileinputstream fis = new fileinputstream("input_file"); bufferedreader br = new bufferedreader(new inputstreamreader(fis, charset.forname("utf-8"))); string line; while ((line = br.readline()) != null) { string split[] = line.split(","); if(split[0].equals("a") { a.add(integer.parseint(split[1])); } else if (split[0].equals("b") { b.add(integer.parseint(split[1])); } else if (split[0].equals("c") { c.add(integer.parseint(split[1])); } } br.close(); fis.close(); //now have finish info set new file. printwriter author = new printwriter("output-file-name", "utf-8"); writer.println("a,b,c"); while(!(a.isempty && b.isempty() && c.isempty())) { stringbuilder sb = new stringbuilder(""); if(!a.isempty()) { sb.append(a.remove(0)); } sb.append(","); if(!b.isempty()) { sb.append(b.remove(0)); } sb.append(","); if(!c.isempty()) { sb.append(c.remove(0)); } writer.println(sb.tostring()); } writer.close(); }

java csv

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -