java - How to turn 2D array rows into a tab separated string when writing an output file -
i have object writing output file.
bufferedwriter bufferedwriter = new bufferedwriter(new filewriter("output.txt")); bufferedwriter.write("id"+"\t"+"symbol"+"\t"+ arrays.tostring(data.symbols)); bufferedwriter.write("\n"); (int = 0; < data.cids.length; i++) { bufferedwriter.write(data.ids[i]+"\t"+data.isymbols[i]+"\t" +arrays.tostring(data.matdata[i])+"\n");
i table in output file:
id symbol [001, 002, 003, 004, 005] #1 a01 [2.3, 5.5, 4.5, 1.2, 3.3] #2 a02 [2.2, 4.5, 7.5, 6.2, 9.3]
...and on. how can display arrays without brackets , tab-separated strings, output this:
id symbol 001 002 003 004 005 #1 a01 2.3, 5.5, 4.5, 1.2 3.3 #2 a02 2.2 4.5 7.5 6.2 9.3
you can implement own tostring method returns tab delimited string
something
public static string tostring(object[] array) { stringbuilder builder = new stringbuilder(); for(object o: array) { builder.append(o+"\t"); } return builder.tostring().trim(); }
Comments
Post a Comment