Results 1 to 3 of 3
  1. #1
    renu is offline Senior Member
    Join Date
    May 2010
    Posts
    117
    Rep Power
    0

    Question How to add a certain number of spaces for each line in the System.out.println

    Hi,

    I create a Audit file within my Java program, which gets all the System.out.println lines from the code.

    For example, the System.out.println lines in my code are as follows:-


    Records initially inserted into edited: 70144
    Bad license number records removed: 5
    Total records in edited: 70139

    Records initially inserted into tabedited:7463

    I want all my values aligned after the statement, when they are printed to the Audit File.



    Instead of just giving spaces by counting the number of charaters in the line, is there any other way to align them.

    Please, let me know.

    Thank U.
    Last edited by renu; 02-07-2014 at 03:59 PM.

  2. #2
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,616
    Rep Power
    5

    Default Re: How to add a certain number of spaces for each line in the System.out.println

    Check out the Format class and its subtypes. Also, consider String.format() and System.out.printf() as possibilities.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  3. #3
    renu is offline Senior Member
    Join Date
    May 2010
    Posts
    117
    Rep Power
    0

    Default Re: How to add a certain number of spaces for each line in the System.out.println

    Thank You Jim.

    But all the format class and its subtypes need the format type followed by the argument.

    My code looks like this
    System.out.println("Records initially inserted into " + tableName + ":" + recordCount);
    Just like the above line, other lines look like this
    System.out.println("Bad license number records removed: " + totalDeleteCount);
    Now I want the number to be aligned in these lines
    within the Audit file.

    And these System out lines are in different Java Classes.
    All will be printed to Audit File.

Similar Threads

  1. Replies: 8
    Last Post: 01-21-2012, 01:14 AM
  2. Replies: 8
    Last Post: 06-21-2011, 02:21 PM
  3. skip a line between 2 system.out.println messages
    By aconti in forum New To Java
    Replies: 5
    Last Post: 05-30-2011, 11:27 AM
  4. Println VS system.out.println
    By ccie007 in forum New To Java
    Replies: 2
    Last Post: 05-20-2010, 08:52 AM
  5. difference between system.out.println() & out.println()
    By wickedrahul9 in forum Advanced Java
    Replies: 5
    Last Post: 10-18-2008, 11:06 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •