java - Alignment Issue in .csv File -
i working on writing of data csv file using java. how can give left alignment each column in csv file?
public class writetofilecsv { public static void main(string[] args) throws ioexception { filewriter fw = new filewriter("writetest.csv"); printwriter out = new printwriter(fw); out.print("this"); out.print(","); out.print("is"); out.print(","); out.print("it's"); out.print(","); out.print("really"); out.print(","); out.flush(); out.close(); fw.close(); } }
you can choose width columns, e.g. 10
, , use format()
:
int width = 10; string columnformat = "%-" + width + "s"; out.format(columnformat, "this"); out.print(","); out.format(columnformat, "is"); out.print(","); ...
Comments
Post a Comment