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

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -