Formatting output to console

I am having problems formatting a series of string outputted to the console. What I am doing looks like this:
Title Title Title Title Title
info info info info info
info info info info info
info info info info info
Each line of 'info' will be read in from a file, but the problem is that the info can vary in length, so there is no way use " " 's to properly align the output so all possible 'info' strings will look good. I know in C++ I could use setW(x) which would help, but I am not aware of anything similiar in Java. Any ideas?
Thanks in advance.

public class Test2 {
  public static void main(String[] args) {
    int[] widths = {12,20,15};
    String[] head = {"One","Two","Three"};
    String[][] data = {{"My dog","has","fleas"},
                       {"Your feline","doesn't have any","Ctenocephalides"}
    // print titles
    for (int i=0; i<head.length; i++) System.out.print(pad(head,widths[i])+" ");
System.out.println();
// print lines
for (int i=0; i<widths.length; i++) {
for (int j=0; j<widths[i]; j++) System.out.print("-");
System.out.print(' ');
System.out.println();
// print data
for (int i=0; i<data.length; i++) {
for (int j=0; j<data[i].length; j++) System.out.print(pad(data[i][j],widths[j])+" ");
System.out.println();
static String pad(String text, int len) {
StringBuffer sb = new StringBuffer(text);
while (sb.length()<len) sb.append(' ');
return sb.toString();

Similar Messages

  • Initial-page-number not working in RTF format output

    A report has a parameter for the page number to start with. In rtf template below code is present
    <?initial-page-number:xdoxslt:ifelse(P_FIRST_PAGE_NUM!=’’,number(P_FIRST_PAGE_NUM),1)?>
    The report page number starts with the value which we pass in p_first_page_num in PDF format but in rtf format output it always starts with 1.
    Is initial-page-number not supported in RTF format output ? If not then what is the alternative?

    the method u followed is fine as need a page number staring from a specify value which u input.
    @section is only for resetting page number to 1 for every group and for that pdf and ppt will be fine but only for rtf u need to use that ( pressing F9).
    u can use @section and initial page number combined but they give u same output as get now. rtf output wont support it will only reset 1 every time
    What ever u do rtf output wont support initial page number code ..........
    i mentioned that F9 work around to mention that it is the only work around u have upto now to control rtf output with regards to page number.
    Guru's correct me if i am wrong. wait for a day or two if some one from guru's confirm it .
    If u need real confirmation raise an SR oracle will let u know .

  • 1.4.2 - What is the correct way to format output in the java.io.PrintStream

    With Java 1.4.2:
    What is the correct way to format output in the java.io.PrintStream?
    The following is incorrect, even though it is still used in the The JavaTM Tutorial at: http://java.sun.com/docs/books/tutorial/essential/
    System.out.formatThis returns "cannot resolve the method 'format'"
    Any detailed suggestions or information is greatly appreciated.

    The following is incorrect, even though it is still
    used in the The JavaTM Tutorial at:
    http://java.sun.com/docs/books/tutorial/essential/
    The whole format thing has been introduced in 1.5. The tutorial also states it's been "updated to 1.5.".
    That's all I've got to say for I don't know how you can format a PrintWriter, let alone a PrintStream, prior to 1.5. I'm not really sure there is any way. Any "legacy way", that is. There almost certainly are third-party API which achieve similar results.

  • List format output to excel sheet

    Hi,
        I have a report output in list format. I need to download that into excel sheet. Is it possible to download a list format output to excel sheet or shall I need to convert that into grid format?
    Thanks Barnita.

    HI,
    Use Menu path
    List->Save/Send->File path

  • SQL Developer formatted output

    Hello,
    Could you please help me in getting the formatted output on Oracle sql developer tool, I am not able to find andy options to set
    I have copy paste the result from this tool to excel, I am getting plain text out put, I have more columns and readablity is not there
    Regards,
    Neil
    Edited by: NeilCSE on Apr 6, 2010 6:01 AM

    Hi,
    try this.
    I am on windows
    SQL> spool c:\emp_text.txt;
    Started spooling to c:\emp_text.txt
    SQL> select ename||'|'||empno from emp;
    ENAME||'|'||EMPNO
    JAMES|7900
    FORD|7902
    MILLER|7934
    SMITH|7369
    ALLEN|7499
    WARD|7521
    JONES|7566
    MARTIN|7654
    BLAKE|7698
    CLARK|7782
    SCOTT|7788
    KING|7839
    TURNER|7844
    ADAMS|7876
    14 rows selected
    SQL> spool off;
    Stopped spooling to c:\emp_text.txtThen open in excel as delimeted by |
    Regards,
    Bhushan

  • How to get XML format output from Hyperion Financial Reporting

    Dears,
    We are using Hyperion Financial Reporting to replace FSG in fusion. I found that Hyperion FR report can be exported to html/excel/pdf format. However, I would like the report to export to xml format.It means I only need the xml data source.
    Anyone who knows how to get the xml format output from Hyperion FR, is there any avaiable API?

    I think if you export the report, you will be able to open the .des file in Notepad/Wordpad and see xml content.

  • Properly formatting output to XML

    While the code below would work to format something simple like this:
    <USERS>
    ��<USER>Tim Smith</USER>
    ��<USER>Jack Dempsey</USER>
    ��<USER>John Doe</USER>
    </USERS>
    hd.startDocument();
    AttributesImpl atts = new AttributesImpl();
    // USERS tag.
    hd.startElement("","","USERS",atts);
    for (int i=0;i<id.length;i++)
      atts.clear();
      hd.startElement("","","USER",atts);
      hd.characters(desc.toCharArray(),0,desc[i].length());
    hd.endElement("","","USER");
    hd.endElement("","","USERS");
    hd.endDocument();
    How does one do more complex nesting of xml elements? Such as if I wanted the output to resemble:
    <USERS>
    ��<USER>Tim Smith</USER>
    ��<ADDRESS>14 Main St</ADDRESS>
    ��<CITY>Denver</CITY>
    ��<STATE>CO</STATE>
    </USERS>
    Message was edited by:
    drakester
    Message was edited by:
    drakester

    I don't quit understand your answer. Serializing objects pertains to formatting output?

  • I am not able to open the html format outputs of SQR

    when I am trying to open SQR html formate output generated by SQR jobs not able to open the html format outputs of SQR getting below error
    but I am able to open pdf and excel formats outputs
    "An error was encountered while attempting to retrieve audit_control_info_frm.htm from the Hyperion Reporting and Analysis - System 9. This error is normally encountered when there is no free disk space on the machine hosting Hyperion Reporting and Analysis - System 9 Application. Hyperion Reporting and Analysis - System 9 Application uses a directory on the hard disk to store temporary files while downloading objects. To rectify this problem, if the disk hosting the Hyperion Reporting and Analysis - System 9 Application temporary directory is nearly full, free up additional disk space. After confirming that there is available disk space, restart ALL Hyperion Reporting and Analysis - System 9 servers. <p>Another possible cause of this error is that you have attempted to embed a "Versioned Collection" into your Personal Page. A "Versioned Collection" is typically created when you publish a document and request the creation of an additional compressed copy. Embedded "Versioned Collections" are not supported by Hyperion Reporting and Analysis - System 9.
    A general error was encountered contacting the server.
    Recommended Action: Contact your corporate technical support."

    Welcome to the Apple community.
    Have you tried restarting your web browser, if that doesn't help you might try emptying your web browser's cache.

  • Can anyone help me understand this output from Console?

    My Macbook Pro freezes and I have to manually shut it down and restart it.  This is the error output from Console after I restart the Mac and find the time that the Mac froze.
    Here is the error code again, if it was too hard to read from the image above:

    Hi, did you find any answer to this? I have the same problem with globeinvestor.com gold tracker program. It stops to run from very beginning and give me a 23 code error.
    Their supprot can not fix this. Actually i have tried this in three different computers and all of them are same.

  • Excel *.xls or *.xlsx for dimension sheet format in Admin Console?

    Dear all:
    We are in the process of upgrading BPC 5.1 to 7.0, and I was prompted a message about the Excel format (2007 or 2003) when I first opened up a dimension in Admin Console, after BPC 7.0 was installed.
    My questions are:
    1. What are the pros and cons?
    2. Excel 2003 has the limitation of 65000 rows, so does that mean once I choose 2003 format, my dimension members can only have 65000 limitation? If not, what is the workaround?
    3. If I select Excel 2007 as my default format, and want to switch to Excel 2003, is there a way to do so?
    Thank you very much!
    Sincerely,
    Brian

    Hi Brian Hsu,
    Please refer to the SAP Note below:
    SAP Note 1265872 - Excel 2007 format template supported in Admin console.
    Summary
    Symptom
    Admin console does not support Excel 2007 format in previous versions.
    Other terms
    BPC 7.0 SP2 Microsoft, BPC 7M SP02, Excel 2007 format(xlsx), Admin console, dimension member sheet,
    Reason and Prerequisites
    The previous version of Admin console supported Excel 2003 file format only. Users could not use Excel 2007 file format ('xlsx').
    Solution
    Implemented in 7.0M SP2.
    BPC Administration console will support both Excel 2003 and Excel 2007
    file format for dimension member sheet. And the BPC Administration
    console uses the value of 'MEMBERSHEET_VERSION' in tblDefaults table
    internally to judge which file format is used for dimension member
    sheet. The value can be "2003" or "2007" and be set by selecting the
    value from popup window as below. Once the value is set via the popup
    window, the value cannot be changed, so we recommend reading the below
    explanation for each case first and then setting the value.
      KeyID and Value in tblDefaults;
        - [KeyID]: MEMBERSHEET_VERSION
        - [VALUE]: "2003" OR "2007"
    Below is the behavior of the Excel version when users try to save a
    dimension member sheet to server or process dimension with member sheet;
    1. No record having MEMBERSHEET_VERSION in tblDefaults after installing
    BPC 7M SP2 or later
       a)Excel 2003 users
         - Download 'xls' file and save to server without any message.
       b)Excel 2007 users
         - A popup window for selecting 2003 or 2007 will come up and if
           user selects 2007, a warning message that Excel 2003 users
           cannot usedimension member sheet file anymore will come up once
           again and then the file format will be changed to 'xlsx'
         - Create, Modify, Copy dimension: The file format of the member
           sheet will be 'xls'.
    2. MEMBERSHEET_VERSION=2003
       a)Excel 2003 users
         - Download 'xls' file and save to server as 'xls'
       b)Excel 2007 users
         - Dimension member sheet file will be saved as 2003 file format by
           'SaveAs'
    3. MEMBERSHEET_VERSION=2007
       a)Excel 2003 users
         - User cannot download dimension member sheet file so cannot use
           dimension member sheet any more.
       b)Excel 2007 users
         - Download 'xlsx' file from server and if there is only 'xls', the
           file will be downloaded from server and then it will be changed         to 'xlsx' when save to server.
         - Create dimension: The file format will be 'xlsx'
         - Modify, Copy dimension: The file format will be followed by the
           downloaded file format.
    [Limitation]
    If the value of MEMBERSHEET_VERSION is set to 2007, users who use Office 2003 cannot access and modify dimension member sheet file any more. Only users who use Office 2007 can access and modify dimension member sheet.

  • HTML formatted output

    Hi All,
    I have xml source as,
    < SAMPLE_JOB>
    < ORG_DESCRIPTION>>& lt;UL& gt;& lt;LI& gt;& lt;DIV class=MsoNormal style=& quot;MARGIN: 0in 0in 0pt 0.25in& quot;
    & gt;& lt;SPAN style=& quot;FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt& quot;
    & gt;Design and deliver technical training courses to field service engineers, dealer, and customer support
    personnel.& lt;/SPAN& gt;& lt;/DIV& gt;& lt;/LI& gt;& lt;/UL& gt;
    < /ORG_DESCRIPTION>
    < /SAMPLE_JOB>
    when i am previewing in pdf output, i am getting the following for < ORG_DESCRIPTION>
    < UL>< LI>< DIV class=MsoNormal style="MARGIN: 0in 0in 0pt 0.25in">< SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Arial;
    mso-bidi-font-size: 12.0pt">Design and deliver technical training courses to field service engineers, dealer, and customer support personnel.< /SPAN>< /DIV>< /
    LI>< /UL>
    I want html formatted output. I saw tims blog. But here in my xml source i am not getting direct tags (instead of "< UL>", i am getting xml output as "& lt; UL & gt;"),
    can i also get the xsl equivalent code for tags like UL, LI, DIV, SPAN..
    Please help me.

    Your XML source is sorta odd.
    Where is it coming from?
    Word?
    This is what your xml should look like:
    < SAMPLE_JOB>
    < ORG_DESCRIPTION>Design and deliver technical training courses to field service engineers, dealer, and customer support
    personnel.< /ORG_DESCRIPTION>
    < /SAMPLE_JOB>
    Then you put it in your rtf and preview in pdf and it would look ok.
    The source xml is the problem - all this stuff is wrong or does not belong:
    & lt;/SPAN& gt;& lt;/DIV& gt;& lt;/LI& gt;& lt;/UL& gt;

  • Formatting output to a file? 1.4.2

    I am writing an application that writes result sets from an oracle 10g database query. This output combines both text and numeric.
    I cannot figure out how to justify the output to the right or left or force the fields to use a set amount of space regardless of the width of the text.
    As a result I get an outfile with perfectly lined up columns except for the one or two where instead of a four digit number there is a single number. This change in width shifts all of the output over.
    My customer goes nuts over this, surely there is a way to format output?

    OK, I tried today, I really did, I just can't get my brain around how to do what I need to accomplish so here is a pseudo example and i am hoping someone can shed some light.
    My application is abstract to enable easy addition of instances of automated reports.
    I have a 2d array that contains the column names for a given query. [0] = column name, [1] = space to be applied after results are added to a string buffer.
    So, something like this:
    StringBuffer entireQueryResults = new StringBuffer();
    String[][] QueryColumns = someObject.getQueryColumnNames();
    ResultSet currResults = someObject.getResultset();
    while(currResults.next()){
    String currRow = "";
    for(int i = 0; i < QueryColumns.length; i++){
       currRow = currRow + currResults.getString(QueryColumns[0])+currResults.getString(QueryColumns[i][1])+"\n";
    entireQueryResults.append(currRow);
    Now, the problem is that there are columns in the queries that have digits, these can range from a single val to 5 and while 98% of them are 3 digits there are random instances where they are a single digit or even a -1. When this happens it throws the output way off and makes it difficult to read in the resulting email report.
    How can I incorporate this into a MessageFormat or ChoiceFormat object to make the output pretty ?

  • Formatting output values

    How can I format output money values to display 2 decimal digits ?
    For examole, for table values 1.20, 2.00 DBMS output displays 1.2 and 2. I want to display all missing zeroes.
    Thanks

    Use a format mask.
    SQL> select to_char(1.2,'999.99') from dual;
    TO_CHAR
    1.20
    SQL> select to_char(2.0,'999.99') from dual;
    TO_CHAR
    2.00

  • Formatted output with JAXB

    Hi, Please help me with the formatting of output XML file using JAXB. This is my client program that marshals xml content into xml file. This program is creating XML file with no indentation at all. I commented out the line
    m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
    still getting same xml file with no indentation. Am I doing anything wrong?
    Thanks in advance.
    try {
    // create a Validator
    Validator v = jc.createValidator();
    // validate the content tree
    boolean valid = v.validate( root );
    //logger.info("XML File Validated Successfully" );
         Marshaller m = jc.createMarshaller();
    m.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, "http://mydomain.com/Schemas/data DT.xsd");
    DataWriter writer = new DataWriter(
    new OutputStreamWriter(new FileOutputStream(fileName),"UTF-8"),
    "UTF-8" );
    m.setProperty("com.sun.xml.bind.namespacePrefixMapper",new NamespacePrefixMapperImpl());
    m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
    m.marshal(root, writer);
    }catch( ValidationException ue ) {
    logger.error( "Caught ValidationException"+ue ); throw new SdarsDBException("Validation Exception "+ue);
    } catch( JAXBException je ) {
    je.printStackTrace();
    } catch( IOException ioe ) {
    ioe.printStackTrace();

    Hi,
    try writing to the FileOutputStream directly.
    I get formatted output this way.
    maybe the DataWriter is doinfg some translatiopn for you?
    Chris

  • Captivate MP4 format output

    Hi,
    I have generated the *.mp4 format output by using captivate 6.0. However, the output quality of the video is not satisfactory. The texts used in the demo are blurred and the image clarity is also not as expected.
    Can someone please help me out in generating a high quality video output.
    Thanks,
    Panendra

    OK.  Well that rules out one of the main reasons people see degradation in output quality,..resizing the content.
    My only other suggestion is that you may need to play around with the publishing settings in Captivate to see if changing something there will improve the quality.

Maybe you are looking for

  • IPhoto email shows question mark instead of email template

    I sent some photos using iPhoto last night, i have gmail account i use to send photos. I learned after i had emailed the photos through iPhoto my receipts received the email with a question mark instead of the iPhoto template. I tried sending a coupl

  • Fluxbox stopped working

    Hey. For some reason fluxbox has stopped working on my box. It's has been working until yesterday when I installed fbpanel, pypanel and xdm (not that I think this is related, just to point out that it was working before I started playing with openbox

  • How to tell if my wifi is working and my phones not using data when Im connected to wifi

    My data is sky high and I have a feeling my wifi isn't worKing... How do I tell if when I'm connected to wifi that it isn't sucking up all my data ?

  • Multi-term searching without using Spotlight.

    How can I search for a file that contains both the word "cat" and "dog", though they aren't next to each other. (So typing "cat dog" into a search field doesn't yield any results) Also, how can I search for all files that contain the word "cat" and h

  • DVD player hangs when I insert blank DVD

    When I insert a DVD into my Mac Pro, the DVD recorder/player stops working!! I have to reboot my machine and it starts working OK. This is happening more and more often. Any Idea why and how to solve the problem?