java - How to add line numbers to input file -



java - How to add line numbers to input file -

so writing method takes in file input , file output. reads input file , adds line numbers lines should read " 1 | line" number right aligned 3 spaces followed number , "|" space before , after it. having problem printing out line. code far is:

public class linenumbers { public static void process(file input, file output) { arraylist<string> fileinput = new arraylist<string>(); arraylist<string> out = new arraylist<string>(); int counter = 0; int counter1= 1; seek { scanner scanner = new scanner(input); printwriter author = new printwriter(output); while (scanner.hasnextline()) { fileinput.add(scanner.nextline()); string = fileinput.get(counter); string line = string.format("%3s | " ,counter1,a); out.add(line); counter++; counter1++; for(string n:fileinput){ writer.println(n); } } scanner.close(); writer.close(); } grab (ioexception e) { } } }

you have:

string.format("%3s | " ,counter1,a);

you pass a parameter have not told string.format() it, , nothing.

i not see format specifier corresponding a. mean:

string.format("%3s | %s" ,counter1,a);

java file-io string-formatting

Comments

Popular posts from this blog

assembly - What is the addressing mode for ld, add, and rjmp instructions? -

vowpalwabbit - Interpreting Vowpal Wabbit results: Why are some lines appended by "h"? -

Is there a way to convert an HTML page styled with Bootstrap CSS into email-compatible html? -