While running the existing code (Below given) I am getting output
Test.txt 00000029, Pistler, Richard
00000034 ,Townley ,Gary
But I want the desired output in the test.txt file like
Test.txt 00000029 Pistler Richard
00000034 Townley Gary
That means pernr _WIDTH is 10 char. For example If it retrives 8 chars from database then
00000034 with two spaces. Similarly laname if it retrives 7 chars from the database then
Pistler with 8 spaces.
Please suggest me how can I handle it from java level.
Please suggest me if there is any function behaving like this.
private static final int pernr _WIDTH = 10;
private static final int laname _WIDTH = 15;
private static final int fname _WIDTH = 15;
Thanks a lot in advance.
posted 9 years ago
Requesting you to Please suggest me for the needful.
Well, if what you need to do is pad your results to be of a specific length, that is very easy to do. You know the required length, and you know the actual length of your String, why don't you simply add the missing characters as needed?
At any rate, there are several ways to do that, but the simplest of all is to use a formatted string, like this:
This would yield
You can read all about padding a String in the Javadoc documentation for java.util.Formatter class.