This week's book giveaway is in the Java in General forum.
We're giving away four copies of Event Streams in Action and have Alexander Dean & Valentin Crettaz on-line!
See this thread for details.
Win a copy of Event Streams in Action this week in the Java in General forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Data is not populated in the file in a proper format

 
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.
 
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!