• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Data is not populated in the file in a proper format

 
Ranch Hand
Posts: 224
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear All,

Requesting you to Please suggest me for the needful.
 
Ranch Hand
Posts: 961
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
These are the worst of times and these are the best of times. And this is the best tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic