I am creating a file by appending all the strings in StringBuilder and then dumping it in a file. But when I check the file (which is obvious) all my strings in each line is not properly align..
Below is the code called by upper layer by passing all the necessary stuff.
private static StringBuilder appendStrings(String pro, List<ProcConfig> list,
StringBuilder sb) {
for (ProcConfig pc : list) {
sb.append(pro).append(" ").append(pc.getNo()).append(" ").append(pc.getId())
.append(" ").append(pc.getAddress()).append(" ").append(pc.getPort()).append(" ")
.append(pc.getNumPorts()).append(" ").append(pc.getName())
.append(System.getProperty("line.separator"));
}
sb.append(System.getProperty("line.separator"));
return sb;
}
And here is how sample lines look like from the above code. After each new line, there is a new set so I want to align all the lines properly in each set before each new line.
config 51 106 10.178.151.25 8095 5 tyt_87612nsas_woqa_7y2_0
config 51 104 10.124.192.124 8080 5 tyt_abc_pz1_rn03c-7vb_01
if_hello_abc_tree tyt.* then process_is_not_necessary 32 80 10.86.25.29 9091 5 tyt_goldenuserappslc22
if_hello_abc_tree tyt.* then process_is_not_necessary 51 50 10.174.192.209 9091 5 tyt_goldenuserapprno01
if_hello_abc_tree tyt.* then config 4 140 10.914.198.26 10001 1 silos_lvskafka-1702600
if_hello_abc_tree tyt.* then config 4 184 10.444.289.138 10001 1 silos_lvskafka-1887568
Is there any way I can align each of the above line properly? So output should be like this:
config 51 106 10.178.151.25 8095 5 tyt_87612nsas_woqa_7y2_0
config 51 104 10.124.192.124 8080 5 tyt_abc_pz1_rn03c-7vb_01
if_hello_abc_tree tyt.* then process_is_not_necessary 32 80 10.86.25.29 9091 5 tyt_goldenuserappslc22
if_hello_abc_tree tyt.* then process_is_not_necessary 51 50 10.174.192.209 9091 5 tyt_goldenuserapprno01
if_hello_abc_tree tyt.* then config 4 140 10.914.198.26 10001 1 silos_lvskafka-1702600
if_hello_abc_tree tyt.* then config 4 184 10.444.289.138 10001 1 silos_lvskafka-1887568
Update:
Below is how it is getting generated now. As you can see on IP Address it is slightly off if you compare the two lines.
config 51 106 97.143.765.65 8095 5 abc_tyewaz1_rna03c-7nhl_02
config 51 104 97.143.162.184 8080 5 abc_tyewaz1_rna03c-7vjb_01
Instead can we generate like below? Basically making each column straight. Is this possible to do?
config 51 106 97.143.765.65 8095 5 abc_tyewaz1_rna03c-7nhl_02
config 51 104 97.143.162.184 8080 5 abc_tyewaz1_rna03c-7vjb_01
"\t"instead of empty string."%-5s%s%n"instead of tab or empty string in my string builder append method? I can't just replace this instead of tab because then it prints that as a string. So I need to plugin this with String.format or anything? Can you tell how I can use it?