• Post Reply Bookmark Topic Watch Topic
  • New Topic

Data is not populated in the file in a proper format

 
sumanta panda
Ranch Hand
Posts: 224
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear All,

While running the existing code (Below given) I am getting output
Output
Test.txt
00000029, Pistler, Richard
00000034 ,Townley ,Gary


But I want the desired output in the test.txt file like
Output
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.


Regards,
Sumanta Panda
 
sumanta panda
Ranch Hand
Posts: 224
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear All,

Requesting you to Please suggest me for the needful.
 
Edwin Dalorzo
Ranch Hand
Posts: 961
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Hope that helps!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!