format - Java output file formatting -


i having bit of trouble formatting output file myself readable. trying output file such as:

name of school                   size of school --------------                   -------------- blblah blah                        1300 blah blah blah                    11300 blah blah blah asdf               14220 blah bblah                         1300 

but having trouble. using following code following output:

file file1 = new file("src\\sortedint.txt"); formatter fmt = new formatter(file1);  helpermethods.quicksortstudents(colleges, 0, colleges.length - 1); for(int = 0; < colleges.length; i++) {       fmt.format(colleges[i].nameofschool + "%20d" + "\n", (int)colleges[i].numofstudents);       fmt.flush(); }   

which gives me:

eastman school of music                 800 clark university                1100 walla walla college                1100 drew                1200 juilliard                1200 

because padding end of college name. there anyway pad whole string strings constant length?

thank help

yep, output college name left-justified , padded length, output number of student right-justified , padded length:

fmt.format("%-20s%10d\n", colleges[i].nameofschool, (int) colleges[i].numofstudents); 

Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -