PrintWriter question- is it possible to print out a table?

Hi everyone,
I am taking the information retrieved from a database and printing it out to a text file using FileOutputStream and PrintWriter. My question is can i format the printout in any way-- like print out certain records in some sort of table, or make some text bold.
I don't know if the code is relevant, so i paraphrased it here:
FileOutputStream fos = new FileOutputStream(x);
PrintWriter w = new PrintWriter(new OutputStreamWriter(fos));
<here i connect to database>
<a couple of w.print() statements and w.println() statements>     
w.close();

You can print data to a file in any form you want. The catch is, as far as i know, you have to lay it out manually. You must convert the data to strings and use white space to lay it out how you want it to look in the text file. Looking over some text I think you would use BufferedWriter to write strings to a file. I don't know any short and easy way, maybe some of the more experienced people will help.
Check the java API on file i/o start at file and work down and see what classes do what you want them to do. If the file is online check the java.net stuff.
If you are trying to print a table to a printer an easy way to do that is make the table in an applet, then print the applet from explorer or netscape.

Similar Messages

  • Is it possible to print out an image that has had a colorMatrixFilter applied to it?

    Is it possible to print out an image that has had a colorMatrixFilter applied to it?
    I applied the following code to print the ViewStack which contain Image
    printJob = new FlexPrintJob();
    printJob.printAsBitmap = true;              
    printJob.addObject(printJobEvent.viewArea, FlexPrintJobScaleType.SHOW_ALL);
    printJob.send();
    Is there any method to print out image with Brightness/Contrast/Hue/Statuation/Rotate adjusted?  Thanks

    If you give the to-do items due dates within the week in question, then checking the "To Dos with Due Dates" option in the calendar pringing dialog will print them. I have not found a way to get To-Dos without a date in the relevant week to print on a weekly calendar.
    Apple ][   Other OS  

  • Printer question: Is it possible to print 2 pages in 1 side paper?

    Printer question: Is it possible to print 2 pages in 1 side paper? If so how ?

    Duplicate post.
    Printer question: Is it possible to print 2 pages in 1 side paper?
    Re: Printer question: Is it possible to print 2 pages in 1 side paper?

  • Is it possible to print out Address Book from a 8310

    Is it possible to print out  Address Book from a 8310, I have backed it up using Desktop Manager.  It is in a .ipd file.  Is their anythin that will read an .ipd file?  Thanks
    Solved!
    Go to Solution.

    Hi and Welcome to the Forums!
    I've heard of a few...can't recall the exact names...Amber something or other? You might try googling to see if you can find anything.
    Good luck and let us know!
    Occam's Razor nearly always applies when troubleshooting technology issues!
    If anyone has been helpful to you, please show your appreciation by clicking the button inside of their post. Please click here and read, along with the threads to which it links, for helpful information to guide you as you proceed. I always recommend that you treat your BlackBerry like any other computing device, including using a regular backup schedule...click here for an article with instructions.
    Join our BBM Channels
    BSCF General Channel
    PIN: C0001B7B4   Display/Scan Bar Code
    Knowledge Base Updates
    PIN: C0005A9AA   Display/Scan Bar Code

  • Is It Possible To Print Out All The Names In Address Book At Once?

    I have got rather a lot of names and email addresses in my Address Book.
    I would like to print them on a few sheets of A4 but the only print options I can find are to print out a single card (with one name) at a time.
    Is it possible to print them all in one go?
    Ian.

    Yes, this is very easy. Select the 'All' group, then choose Print from the File menu. Choose your printing options from the menus and send it to your printer.
    Mulder
    If this answered you question, please consider awarding some points. Why Reward Points?
    iMac G4 700Mhz   Mac OS X (10.3.9)  

  • Is it possible to print out the notes taken in the notes widget?

    I want the user to be able to print out the notes they have taken. Is this possible?
    Thanks?

    Hi
    I had asked a query on the same lines. You can check out the replies from Adobe here.
    http://forums.adobe.com/thread/1296862?tstart=0
    As I have mentioned in my last post in that thread, the biggest disadvantage of Notes interaction is that it is deleted when the users clear their browser cache.
    Sreekanth

  • Is it possible to print out song listin

    I've tried to print out the songs I have on my Zen Touch through the Creative Organizer but can't seem to do it. I tried highlighting a listing then copy and paste but no go. Has anyone done this? Is it possible? If not, I would like a printing option made available.
    Dan

    It's not possible through MediaSource. Notmad Explorer has a good reporting tool, but is shareware.

  • Unable to print out invoice spec, it shows but is not possible to print

    It's not possible to print out the e-invoicespec. I am logged in to my internet bank (SEB). The page is imported from an external source and is shown but is not possible to print out.
    With Int Explorer printing is possible by a right mousepress

    * [[Printing a web page]]
    * [[Firefox prints incorrectly]]
    Check and tell if its working.

  • Is it possible to print a JPanel from the application?

    Hello,
    Just a quick question: Is it possible to print a JPanel from your application? I have plotted a graph and I would like user to be able to print this with a click of a button (or similar)
    Thanks very much for your help, its appreciated as always.
    Harold Clements

    It is absolutely possible
    Check out my StandardPrint class. Basically all you need to do is
    (this is pseudocode. I don't remember the exact names of methods for all this stuff. Look it up if there's a problem)
    PrinterJob pd = PrinterJob.createNewJob();
    StandardPrint sp = new StandardPrint(yourComponent);
    pd.setPageable(sp);
    //if you want this
    //pd.pageDialog();
    pd.doPrint();You are welcome to have use and modify this class but please don't change the package or take credit for it as your own code.
    StandardPrint.java
    ===============
    package tjacobs.print;
    import java.awt.*;
    import java.awt.image.BufferedImage;
    import java.awt.print.*;
    import javax.print.PrintException;
    public class StandardPrint implements Printable, Pageable {
        Component c;
        SpecialPrint sp;
        PageFormat mFormat;
         boolean mScale = false;
         boolean mMaintainRatio = true;
        public StandardPrint(Component c) {
            this.c = c;
            if (c instanceof SpecialPrint) {
                sp = (SpecialPrint)c;
        public StandardPrint(SpecialPrint sp) {
            this.sp = sp;
         public boolean isPrintScaled () {
              return mScale;
         public void setPrintScaled(boolean b) {
              mScale = b;
         public boolean getMaintainsAspect() {
              return mMaintainRatio;
         public void setMaintainsAspect(boolean b) {
              mMaintainRatio = b;
        public void start() throws PrinterException {
            PrinterJob job = PrinterJob.getPrinterJob();
            if (mFormat == null) {
                mFormat = job.defaultPage();
            job.setPageable(this);
            if (job.printDialog()) {
                job.print();
        public void setPageFormat (PageFormat pf) {
            mFormat = pf;
        public void printStandardComponent (Pageable p) throws PrinterException {
            PrinterJob job = PrinterJob.getPrinterJob();
            job.setPageable(p);
            job.print();
        private Dimension getJobSize() {
            if (sp != null) {
                return sp.getPrintSize();
            else {
                return c.getSize();
        public static Image preview (int width, int height, Printable sp, PageFormat pf, int pageNo) {
            BufferedImage im = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
            return preview (im, sp, pf, pageNo);
        public static Image preview (Image im, Printable sp, PageFormat pf, int pageNo) {
            Graphics2D g = (Graphics2D) im.getGraphics();
            int width = im.getWidth(null);
            int height = im.getHeight(null);
            g.setColor(Color.WHITE);
            g.fillRect(0, 0, width, height);
            double hratio = height / pf.getHeight();
            double wratio = width / pf.getWidth();
            //g.scale(hratio, wratio);
            try {
                   sp.print(g, pf, pageNo);
              catch(PrinterException pe) {
                   pe.printStackTrace();
            g.dispose();
            return im;
        public int print(Graphics gr, PageFormat format, int pageNo) {
            mFormat = format;
            if (pageNo > getNumberOfPages()) {
                return Printable.NO_SUCH_PAGE;
            Graphics2D g = (Graphics2D) gr;
              g.drawRect(0, 0, (int)format.getWidth(), (int)format.getHeight());
            g.translate((int)format.getImageableX(), (int)format.getImageableY());
            Dimension size = getJobSize();
              if (!isPrintScaled()) {
                 int horizontal = getNumHorizontalPages();
                 int vertical = getNumVerticalPages();
                 int horizontalOffset = (int) ((pageNo % horizontal) * format.getImageableWidth());
                 int verticalOffset = (int) ((pageNo / vertical) * format.getImageableHeight());
                 double ratio = getScreenRatio();
                 g.scale(1 / ratio, 1 / ratio);
                 g.translate(-horizontalOffset, -verticalOffset);
                 if (sp != null) {
                     sp.printerPaint(g);
                 else {
                     c.paint(g);
                 g.translate(horizontal, vertical);
                 g.scale(ratio, ratio);
              else {
                 double ratio = getScreenRatio();
                 g.scale(1 / ratio, 1 / ratio);
                   double xScale = 1.0;
                   double yScale = 1.0;
                   double wid;
                   double ht;
                   if (sp != null) {
                        wid = sp.getPrintSize().width;
                        ht = sp.getPrintSize().height;
                   else {
                        wid = c.getWidth();
                        ht = c.getHeight();
                   xScale = format.getImageableWidth() / wid;
                   yScale = format.getImageableHeight() / ht;
                   if (getMaintainsAspect()) {
                        xScale = yScale = Math.min(xScale, yScale);
                   g.scale(xScale, yScale);
                   if (sp != null) {
                        sp.printerPaint(g);
                   else {
                        c.paint(g);
                   g.scale(1 / xScale, 1 / yScale);
                   g.scale(ratio, ratio);
             g.translate((int)-format.getImageableX(), (int)-format.getImageableY());     
            return Printable.PAGE_EXISTS;
        public int getNumHorizontalPages() {
            Dimension size = getJobSize();
            int imWidth = (int)mFormat.getImageableWidth();
            int pWidth = 1 + (int)(size.width / getScreenRatio() / imWidth) - (imWidth == size.width ? 1 : 0);
            return pWidth;
        private double getScreenRatio () {
            double res = Toolkit.getDefaultToolkit().getScreenResolution();
            double ratio = res / 72.0;
            return ratio;
        public int getNumVerticalPages() {
            Dimension size = getJobSize();
            int imHeight = (int)mFormat.getImageableHeight();
            int pHeight = (int) (1 + (size.height / getScreenRatio() / imHeight)) - (imHeight == size.height ? 1 : 0);
            return pHeight;
        public int getNumberOfPages() {
              if (isPrintScaled()) return 1;
            return getNumHorizontalPages() * getNumVerticalPages();
        public Printable getPrintable(int i) {
            return this;
        public PageFormat getPageFormat(int page) {
            if (mFormat == null) {
                PrinterJob job = PrinterJob.getPrinterJob();
                mFormat = job.defaultPage();
            return mFormat;
    }

  • How do I get System.out.format to print out doubles with the same precision

    Using the System.out.format, how do I print out the value of a double such that it looks exactly like it does if it were print from a System.out.println.
    For example, take the following code:
    double d = 12.48564734342343;       
    System.out.format("d as format: %f\n", d);
    System.out.println("d as   sout: " + d);Running the code, I get:
    <font face="courier">
    d as format: 12.485647
    d as sout: 12.48564734342343
    </font>
    The precision of d has been lost.
    I could bump up the precision as follows:
    double d = 12.48564734342343;
    System.out.format("d as format: %.14f\n", d);
    System.out.println("d as   sout: " + d);That appears to work, I get:
    <font face="courier">
    d as format: 12.48564734342343
    d as sout: 12.48564734342343
    </font>
    However, that solution fails if d has a different precision, say 12.48. In that case I get:
    <font face="courier">
    d as format: 12.48000000000000
    d as sout: 12.48
    </font>
    So how do I get System.out.format to print out doubles with the same precision as System.out.println?
    Thanks..

    YoungWinston wrote:
    Schmoe wrote:
    Interesting, but this is not what I am looking for...Your original question was "how do I print out the value of a double such that it looks exactly like it does if it were print from a System.out.println", and you've been told how to do that (although the pattern given by sabre may be a bit excessive - you should only need 15 '#'s).The initial phrase from my question was "Using the System.out.format, how do I..".
    It's worth remembering that, unlike the Format hierarchy, 'format()' is NOT native to Java. It's a convenience implementation of the 'printf()' and 'sprintf()' methods provided in C, and first appeared in Java 1.5. Those methods were designed to produced fixed-format output; 'println()' was not.Perhaps it is the case that this can't be done.
    Furthermore, Double.toString(), which is what is used by println() does not produce the same format in all cases; format("%.14f\n", d) does. TrySystem.out.println(1.8236473845783d);
    System.out.println(1823647384.5783d);and you'll see what I mean.I am fine with that. It still displays all the precision.
    I am simply looking for a way to quickly print out multiple variables on a sysout while debugging. I want it as syntactically sweet as possible. System.out.println can be a pain when outputting multiple variables like the following:
    "System.out.println("a: " + a + "; b:" + b + "; c: " + c);"
    For some reason, my fingers always typo the plus key.
    I was hoping that System.out.format would be easier,along the lines of:
    "System.out.format("a: %f, b: %f, c: %f\n", a, b, c);"
    From a syntactical sweetness point of view, it is easier. However, the %f on doubles truncates the precision. I figured there must be a way to get the full precision.
    DecimalFormat is syntactically sour for this purpose, as you need to instantiate the DecimalFormat.
    fwiw I have enjoyed reading the suggestions in this thread...

  • Automatic print out of a document that is created via B1iSN

    Can anybody tell me if it is possible to print out of a document (purchase invoice) automatically after it has been created via B1iSN?
    Does anyone have an example or a link how to realize this?
    Thanks
    Gerhard.

    Hi Gordon,
    thanks for your fast reply.
    we have a subsidiary A that does all the accounting and sales for subsidiary B (that works as a commercial unit). All goods that are sold in B are purchased in A. We have connected the two subsidiaries via B1i. A sales order in B automatically generates a purchase order that is send to A via B1i (B1PO2B1SO scenario). The invoice from A for these goods is send to B as a purchase invoice via B1i.
    This purchase invoice ought to be printed out automatically as the staff and printers are in the same office.
    Regards,
    Gerhard.

  • Print out of item line in sales order

    Dear all,
    I hope someone can help me.
    In a sales order, if I open the menu
      Extras-->Output
    I can choose between Header and Item.
    Where are the differences here.
    Is it possible to print out only a highlighted item line by using
      Extras>Output>Item-->Edit?
    Thank you very much in advance.
    Andreas

    This is not possible in the standard system.
    One possible way could be to create a custom header output program (ex. one copied from BA00 outut) that reads in some way the checked items, or you can set some item field (ex. Additional data tile fields) and the read this field in the header output.
    Hope this can help you.
    regards
    Roberto Mazzali

  • Print out Bill of material

    How it's possible to print out a bill of material
    Thanks in advance
    Regards
    Andrea

    Hi
    you try any of CS11,CS12,CS13.
    After you get the report on the screen , follow the path
    Extras--> List ---> Print.
    You can print.
    Regards
    YMREDDY

  • Print out a page with a all controls

    Hello
    Is it possible to print out all the controls on a page.
    I meam all together with one function?
    Thanks
    Phil1

    I assume you're asking how do you print an MFC dialog with all of its controls. Is that correct? If so, try adding a method to your dialog class with this code:
    CPrintDialog printDlg(FALSE);
    if (printDlg.DoModal() != IDOK)
    return;
    DOCINFO documentInfo;
    ::ZeroMemory(&documentInfo, sizeof(documentInfo));
    documentInfo.cbSize = sizeof(documentInfo);
    documentInfo.lpszDocName = _T("Dialog Document");
    HDC hdcPrinter = printDlg.GetPrinterDC();
    CDC printerDC;
    printerDC.Attach(hdcPrinter);
    printerDC.StartDoc(&documentInfo);
    printerDC.StartPage();
    HDC hdcScreen = ::GetDC(NULL);
    CDC screenDC;
    screenDC.Attach(hdcScreen);
    long screenPpiX = ::GetDeviceCaps(hdcScreen, LOGPIXELSX)
    long screenPpiY = ::GetDeviceCaps(hdcScreen, LOGPIXELSY);
    long printerPpiX = ::GetDeviceCaps(hdcPrinter, LOGPIXELSX);
    long printerPpiY = ::GetDeviceCaps(hdcPrinter, LOGPIXELSY);
    long xRatio = printerPpiX / screenPpiX;
    long yRatio = printerPpiY / screenPpiY;
    CRect windowRect;
    GetWindowRect(&windowRect);
    CRect targetRect = windowRect;
    targetRect.right = targetRect.left + (targetRect.Width() * xRatio);
    targetRect.bottom = targetRect.top + (targetRect.Height() * yRatio);
    targetRect.OffsetRect(
    -targetRect.left + (targetRect.left * xRatio),
    -targetRect.top + (targetRect.top * yRatio)
    CDC* dialogDC = GetDC();
    printerDC.StretchBlt(
    0,
    0,
    targetRect.Width(),
    targetRect.Height(),
    dialogDC,
    0,
    0,
    windowRect.Width(),
    windowRect.Height(),
    SRCCOPY
    ReleaseDC(dialogDC);
    screenDC.Detach();
    p
    rinterDC.EndPage();
    printerDC.EndDoc();
    printerDC.Detach();
    This isn't perfect, but hopefully it can get you started.
    - Elton

  • Print out name of Approver

    Dear Experts,
    On an approved document - say Purchase Order is it possible to print out the names of the people who approved it using crystal report layouts on SAP 8.8 ?
    Regards,

    Hi Martin,
    You can do it in Crystal report. refer following query
    select po.Docnum,po.docdate,orgus.u_name as 'Generated By',appus.u_name as 'Approved By' from opor po
    inner join owdd ow on po.objtype=ow.objtype and po.docentry=ow.docentry
    inner join wdd1 w1 on ow.wddcode=w1.wddcode
    inner join ousr appus on w1.userid=appus.userid
    inner join ousr orgus on w1.usersign=orgus.userid
    Thanks
    SD

Maybe you are looking for

  • Service PR Creation

    Hi,      I am working on Service Purhase Requistion creation.For this i am using BAPI_REQUISTION_CREATE.If i am giving incorrect input values system immedatily showing the error.whenver i am giving correct input values.system at status bar its displa

  • Photo Booth green screen

    I tried tonight to open photo booth but it has just a green screen. When I takea photo the camera button is red abd although it goes into countdown it take a green page as the photo. camera is working as it looks fine in ichat. I have trashed the pho

  • E63 not receiving email automatically

    Please! Somebody help me. I live in Kenya and I have been sending email from my phone and receiveing my email from my hotmail account directly to my phone as well since Dec 09. All of a sudden (April '11) the emails stop synching! I've checked all my

  • Probleem in converting the asset under construction/WIP to expenditure

    Hi When I am trying to post a transaction through F-43, to convert the Asst under construction/WIP to expenditure by Credit the asset - Transaction type 101 I get the error - Acquisition value negative in area 01 (message AA 617) This problem is face

  • Iphoto 08 does not save noise or sharpness

    I have just discovered that iPhoto 08 does not save noise or sharpness adjustments. What the heck...is there a "fix" for this yet?