Java-Ausgabe-Datei-Formatierung

Bin ich mit ein bisschen Mühe Formatierung einer Ausgabedatei für mich leicht lesbar. Ich versuche die Ausgabe der Datei, wie zum Beispiel:

Name of School                   Size of School
--------------                   --------------
Blblah blah                        1300
Blah blah blah                    11300
Blah blah blah asdf               14220
Blah bblah                         1300

aber ich habe Probleme. Momentan benutze ich den folgenden code, um die folgende Ausgabe erhalten:

File file1 = new File("src\\sortedInt.txt");
Formatter fmt = new Formatter(file1);

HelperMethods.quickSortStudents(colleges, 0, colleges.length - 1);
for(int i = 0; i < colleges.length; i++)
{
      fmt.format(colleges[i].nameOfSchool + "%20d" + "\n", (int)colleges[i].numOfStudents);
      fmt.flush();
}  

gibt mir:

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

Da bin ich einfach padding von der Ende der college-Namen. Ist es irgendwie pad den ganzen string also alle Saiten sind eine Konstante Länge?

Danke an alle für dich Hilfe

InformationsquelleAutor Brendan | 2011-04-28
Schreibe einen Kommentar