java - Print writer format -
i have list several objects each containing 3 strings
, how should format output (in outfile.format()
) make in sample output below?
public void save() { try { printwriter outfile = new printwriter (new bufferedwriter (new filewriter("reg_out.txt"))); (int = 0; < list.size(); i++) { outfile.format("???", list.get(i).getlastname(), list.get(i).getfirstname(), list.get(i).getnumber()); } outfile.close(); } catch (ioexception ioe) { ioe.printstacktrace(); } }
sample output in reg_out.txt:
allegrettho albert 0111-27543 brio britta 0113-45771 cresendo crister 0111-27440
try this
outfile.printf("%-20s%-20s%-20s%n", list.get(i).getlastname(), list.get(i).getfirstname(), list.get(i).getnumber());
see java.util.formatter api details
Comments
Post a Comment