PrintWriter - print methods

Hi I am trying to print an address book to a file and am
having some trouble. I'm not familiar with writing
objects to a file. Any suggestions?
Here is my abbreviated code:
// type of address book
OrderedLinkedList<ExtPerson> addBook
                 = new OrderedLinkedList<ExtPerson>();
// read in file of addresses
        Scanner inFile = new Scanner(new FileReader("c:\\addressList.txt"));
// to write the file to the c drive
        PrintWriter outFile = new PrintWriter("c:\\addressBook.txt");
     // menu driven search program
   Boolean token1 = false;
   while(!token1) {
   System.out.println();
   System.out.println("To add a new entry to the address book, enter 1.\n"
            + "To print the address book, enter 2.\n"
            + "To delete an entry from the address book, enter 3.\n" +
            "To exit, enter 0.\n");
    int token2 = console.nextInt();
    switch (token2) {
        case 0: // to exit
            token1 = true;
            outFile.println(addBook);
            outFile.close();
            break;

What are you using to view the file? If it's Notepad on Windows, then you'll probably be seeing little squares where the newline is supposed to be. This is because Notepad doesn't recognize "\n" as a newline, it only works for "\r\n".
Try viewing the file in some other editor (I personally use [Notepad++|http://notepad-plus.sourceforge.net/uk/site.htm], and incidentally, it's the first result when you Google for notepad), maybe Wordpad or Word. You should see the correct output.
You can also try using System.line.separator to get the system specific line separator. But keep in mind that this will potentially give you different files on different OSs - you'll get the same output you're getting right now on a *nix system and so you'll have the same problem. I'd recommend just ignoring Notepad and continue using "\n"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

Similar Messages

  • Printed front panel graphics quality (Print Panel to Printer method vs. Append Front Panel Image to Report.vi)

    LV 6.02 (or 6.1)
    NT 4.0
    I have a vi that the front panel includes all the information I need to print except that it is on different pages of a tab control to conserve screen space. I was attempting to programatically cycle the value of the tab control in a For loop and invoke the Print Panel to Printer method to print 7 pages of the front panel, each with a different tab page selected. The printouts were excellent quality but beginning with the second consecutive Print Panel to Printer method the on screen front panel image of the VI being printed would become jumbled (sometimes, by the time 7 printings were done, the entire front panel image would disappe
    ar and a bitmap of the desktop or underlying windows would be visible in the VI's panel frame) yet the subsequent Print Panel to Printer methods continued to print the panel as they should appear. The visible front panel graphics would never return to normal and the only solution was to close the vi (in the dev system) or exe (compiled) and re-launch. I tried a lot of things (like hiding the panel to print before printing and showing it after printing) with no luck. It appears that two or more of these consecutive invoke methods caused the problem regardless of whether the tabs were cycling, or even if there was no tab control and much fewer controls on the panel to be printed than normal. I also had the same problem with LV 6.1.
    Finally, I was forced to switch to the report generation toolkit vi's, I cycle through the tab pages and use the Append Front Panel Image to Report.vi to append each image to the report. This is faster and control returns to my program quicker but I a
    m unhappy with the printed quality of the graphics of the front panels. They are not as high of resolution as those generated via the Print Panel to Printer method.
    Any suggestions?

    You might try changing the way the VI is printed by going to tools >> options >> printing. Try the postscript and bitmap settings.
    Jeremy

  • Help reqd to display the FORM without Print method.

    Hi all,
    I did one gate pass form and i want to view the form in my selection screen or output screen(just in monitor) as  a display by giving one Z-code.
    i.e, we can view the form thru Print preview...the same preview, i want to display after i give my parameter in the selection screen.
    For example.ZGPOUT if i enter as a t-code.
    it should ask my Gate Pass number in the Selection screen...if its right then my Form will come out to the display screen. (instead of going by Print method).,
    Pls post ur comment and reply me with examples,if possible.
    thanks & regards
    sankar.

    Hi Sankar,
    Its bit ambigious......but logic is very simple...........
    1. Create a Z.....report
    2. Inside this create your selection parameters
    3. Do your logic for the selection screen(use list box option or F4 help) to ask for the gate pass number.
    4. Call the required form. (For print preveiw assign 'X' to tdpreview of ITCPO)
    5. Finally assign your print program to the tcode which will finally do rest of the coding.
    Thanks,
    Mark

  • Binary Tree search and print methods

    Hello, I'm trying to create a binary tree from inputs of a user. I believe I have the tree set up right because it shows no errors, but I'm getting an error message with a line of code. I cannot figure out what I am doing wrong. Also, I need to create a print method, which prints the tree's entries and a search method which would search the tree for certain record.
    public class TreeNode 
          public static String empName = null;
          public static int empNumber;
          public static String nextRec = null;
              TreeNode left;
          String Name;
          int Number;
          TreeNode right;
          public static void main(String[] args)
             VRead in = new VRead();
             VWrite out = new VWrite();
             System.out.println("Enter Choice: ");
             System.out.println("A: Enter Employee Information.");
             System.out.println("B: Search For Employee.");
             System.out.println("C: Print Entire Tree.");
             System.out.println("D: Exit.");
             System.out.println("_______________________________");
             char command = in.readChar();
             System.out.println();
             switch (command)
                case 'A':
                case 'a':
                   inputInfo(in, out);           
                   break;
                case 'B':
                case 'b':
                   break;
                case 'C':
                case 'c':
                   break;
                case 'D':
                case 'd':
                   System.exit(0);
                   break;
          public static void inputInfo(VRead in, VWrite out)
             out.write("Enter Employee Name: ");
             empName = in.readString();
             out.write("Enter Employee Number: ");
             empNumber = in.readInt();
             System.out.println();
             System.out.println();
             System.out.println("Enter Choice: ");
             System.out.println("A: Enter Employee Information.");
             System.out.println("B: Search For Employee.");
             System.out.println("C: Print Entire Tree.");
             System.out.println("D: Exit.");
             System.out.println("_______________________________");
             char command = in.readChar();
             System.out.println();
             switch (command)
                case 'A':
                case 'a':
                   inputInfo(in, out);           
                   break;
                case 'B':
                case 'b':
                   break;
                case 'C':
                case 'c':
                             break;
                case 'D':
                case 'd':
                   System.exit(0);
                   break;
          public TreeNode(String empName, int empNumber)
             Name = empName;
             Number = empNumber;
             left = null;
             right = null;
          public class Tree
             TreeNode Root;
             public void Tree(String RootNode)   
        // Errors come from next line
                  Root = new TreeNode(RootNode, Name, Number);   
             public void Insert(String Name, int Number)
                InsertNode(Root, Name, Number);
             public void InsertNode(TreeNode t, String empName, int empNumber)
                if (t == null)
                   t = new TreeNode(empName, empNumber);
                else
                   if (empName.compareTo(t.Name) < 0)
                      InsertNode(t.left, empName, empNumber);
                   else if (empName.compareTo(t.Name) > 0)
                      InsertNode(t.right, empName, empNumber);
                   else if (empName.compareTo(t.Name) == 0)
                      System.out.println("Entered node that was already in Tree");
       }im sure its something simple, i seem to always look over the small stuff. But i could really use some help on the print and search method too

    Just having a quick look over it, and it looks like you are trying to add an extra argument in the TreeNode() method (unless there is a bit of overloading and there is a second treenode method in there) As it is TreeNode only accepts two argumets you have 3
    As for printing the tree you would need to flatten it, that is an in order traversal of the tree.
    FWIW
    I just finished a project at uni that involved at frist writing a BST and then an AVL tree. the full point of these things seems to be to keep students awake at night*
    *Before anyone flames, it's a joke
    G

  • Help me with the right print method?

    I have several pages of data in my database that I need to print. The printing should have header and footer, and print several pages. My question is which print method should I use and how? Am offering 2 Duke Dollars for this...

    come on guys a little help plz.... :-(

  • Print methods of a class at run-time

    Suppose I have a class. At run-time I get an object of that class. I want to print methods defined in that object using System.out.println(). How can I do that?
    Thanks

    Take a look at Object.getClass(). It returns a Class object. Then look at the methods within the Class class that you can invoke. Some of them return arrays of Method objects, for instance.
    Learn to read the API and experiment with the available methods you already have (such as getClass(), available for every object).
    http://java.sun.com/j2se/1.4.2/docs/api/index.html

  • I run into an infinite loop when I try and use this print method

    Hi,
    I have the following class. If i run it in stand alone, everything works out great. However, if I call it from a much larger application (which is why I have built this class), I run into an infinite loop. I have no idea why, but I have pinpointed it to the line: tableView.getTableHeader().paint(g2);
    Any help is greatly appreciated. I have been tryin to figure this out for a week now, and I havent gotten anywhere. It makes no sense to me, since this works as a standalone application, but if i put a method similar to the main() inside a much larger application, I end up with an inifinite loop.
    Thanks again!
    import javax.swing.table.AbstractTableModel;
    import javax.swing.*;
    import java.awt.print.*;
    import java.awt.*;
    import java.util.Iterator;
    import java.util.ArrayList;
    public class printTableTest implements Printable, Pageable {
         private PageFormat pf;
         private String[] headers = { "Heading 1", "Heading 2", "Heading 3"};
         private ArrayList<Object[][]> data = new ArrayList<Object[][]>();
         public printTableTest(PageFormat format) {
              this.pf = format;
                                               this.setObjects();
         public int getNumberOfPages() {
            return 1;
        public PageFormat getPageFormat(int pageIndex) throws IndexOutOfBoundsException {
            return pf;
         public void setObjects() {
              for(int x=0; x < 3; x++) {
                   int ndx = 0;
                   Object[][] tempData = new Object[2][3               for (; ndx < 2 ; ) {
                        tempData[ndx] = new Object[] { "col 1: " + x, "col 2: " + x, "col 3: " + x };
                        ndx++;
                   data.add(tempData);
        public Printable getPrintable(int pageIndex) throws IndexOutOfBoundsException {
            return this;
         public int print(Graphics g, PageFormat format, int pageIndex) throws PrinterException {
              JFrame frame = null;
              JTable tableView = null;                                                       System.err.println("here");
              Graphics2D g2 = (Graphics2D) g;
              //Object[][] data = new Object[3][3];
              g2.setColor(Color.black);
              g2.translate(format.getImageableX() + 72, format.getImageableY() + 72);
              for(int x=0; x < data.size(); x++) {
                   tableView = new JTable(new PrintTableModel(headers, data.get(x)));
                   frame = new JFrame();
                   JScrollPane scrollpane = new JScrollPane(tableView);
                   scrollpane.setPreferredSize(new Dimension(300, 80));
                   frame.getContentPane().setLayout(new BorderLayout());
                   frame.getContentPane().add(BorderLayout.CENTER,scrollpane);
                   frame.pack();
                   tableView.paint(g2);
                   g2.translate(0, - tableView.getTableHeader().getHeight());
                   tableView.getTableHeader().paint(g2);
                   g2.translate(0, format.getImageableHeight()/3);
              return Printable.PAGE_EXISTS;
         public static void main(String args[]) {
             PrinterJob printerJob = PrinterJob.getPrinterJob();
              printTableTest pp = new printTableTest( printerJob.defaultPage());
              printerJob.setPageable(pp);
              boolean doPrint = printerJob.printDialog();
              if (doPrint) {
                   try {
                        printerJob.print();
                   } catch (PrinterException exception) {
                        System.err.println("Printing error: " + exception);
             System.exit(0);
         private class PrintTableModel extends AbstractTableModel {
              private Object[][] data = null;
              private String[] headers = null;
              public PrintTableModel(String[] headers, Object[][] data) {
                   this.headers = headers;
                   this.data = data;
              public int getColumnCount() { return headers.length; }
              public int getRowCount() { return data.length; }
              public Object getValueAt(int row, int col) { return data[row][col]; }
              public String getColumnName(int column) { return headers[column]; }
              public Class getColumnClass(int col) { return getValueAt(0,col).getClass(); }
              public boolean isCellEditable(int row, int col) { return false; }
              public void setValueAt(Object aValue, int row, int column) { data[row][column] = aValue; }
    }

    Log the parameters passed to my print method?
    The only parameter that would be relevant would be the pageNumber, and I can tell you that it continues to loop. Here is an example of the output:
    Page: 0
    Page: 0
    Page: 0
    Page: 0
    Page: 0
    Page: 0
    Page: 0
    Page: 0
    Page: 0
    Page: 0
    Page: 0
    Page: 0
    Page: 0
    Page: 0
    Page: 0
    Page: 0
    Page: 0
    Page: 0
    Page: 0
    Page: 0
    Page: 0
    Page: 0
    Page: 0
    Page: 0
    Page: 0
    Page: 0
    Page: 0
    Page: 0
    Page: 0
    Page: 0
    Page: 0
    Page: 0
    Page: 0
    Page: 0
    Page: 0
    Page: 0
    Page: 0
    Page: 0
    Page: 0
    Page: 0
    and here is the Thread Trace:
    AWT-EventQueue-0@42f prio=6, in group "main", status: WAIT
           wait():-1, Object.java
           wait():474, Object.java
           getNextEvent():345, EventQueue.java
           pumpOneEventForHierarchy():189, EventDispatchThread.java
           pumpEventsForHierarchy():163, EventDispatchThread.java
           pumpEvents():157, EventDispatchThread.java
           pumpEvents():149, EventDispatchThread.java
           run():110, EventDispatchThread.java
    AWT-Shutdown@430 prio=5, in group "main", status: WAIT
           wait():-1, Object.java
           wait():474, Object.java
           run():259, AWTAutoShutdown.java
           run():595, Thread.java
    Java2D Disposer@2a0 daemon prio=10, in group "main", status: WAIT
           wait():-1, Object.java
           remove():116, ReferenceQueue.java
           remove():132, ReferenceQueue.java
           run():107, Disposer.java
           run():595, Thread.java
    AWT-Windows@fc daemon prio=6, in group "main", status: RUNNING
           eventLoop():-1, WToolkit.java
           run():269, WToolkit.java
           run():595, Thread.java
    Signal Dispatcher@2a2 daemon prio=10, in group "system", status: RUNNING
    Finalizer@2a3 daemon prio=8, in group "system", status: WAIT
           wait():-1, Object.java
           remove():116, ReferenceQueue.java
           remove():132, ReferenceQueue.java
           run():159, Finalizer.java
    Reference Handler@2a4 daemon prio=10, in group "system", status: WAIT
           wait():-1, Object.java
           wait():474, Object.java
           run():116, Reference.java
    main@1 prio=5, in group "main", status: RUNNING
           print():68, printTableTest.java
           redrawRegion():906, WPathGraphics.java
           printPage():1817, RasterPrinterJob.java
           print():1334, RasterPrinterJob.java
           print():1196, RasterPrinterJob.java
           main():1922, TOLMainFrame.java

  • Frontend printing method G question.

    Hi All,
    is it possible to print on frontend workstation using method "G" but bypassing windows printer selection dialog box?
    Thanks in advance.
    Jacek

    Check out SAP Note # 938965.  I think it might solve your problem: 
    <i>Printer checkbox can be deactivated with access method "G" You want to be able to deactivate the printer checkbox with access method "G". For this purpose, you have to select the checkbox for the non-selection of devices on the front end when defining the printer in Transaction SPAD.</i>
    Regards,
    John

  • Print() method takes into account Acrobat's settings

    Hello,
    While I print a document using the Javascript method then the AutoRotate setting which is stored in the registry key of the computer is taken into account.
    I mean that it's not possible to force auto-rotate while the bprintAutoRotate registry key is set to false (to set it you just have to open Acrobat and print a document without selecting auto-rotate - to remove it just make the opposite).
    Is it normal? By the other hand while the auto-rotate is set to true then I just have to add the flags : suppressCenter and suppressRotate.
    Thanks in advance,
    Joe

    Dear user,
    You are getting such output because you have checked ON the setting 'Print to file' in one of your previous prints. For resolving this issue, kindly uncheck option 'Print to file' present in bottom left corner of print dialog and then click on 'Print' (See attached image for reference).
    Hope this will solve your problem.
    Thanks
    sonal

  • Print method!!!!!!!!!

    Hi,
    i'm creating an web application for my accademic, in which i have an jsp page with a print page.
    e.g. A page containg a form with a print button,when the print button is pressed tht page should be printed.
    "is there any method to call the printer".
    can any1 help me with this.
    Thanks.
    vj.

    Hi
    Use
    <input type='button' name='print' value='Print' onClick='javascript:print();'>
    HTH
    VJ

  • AP Check Printing Methods

    Dear All,
    If check is printed one time then next time printed check will not be shown or display in check report. Is Oracle provide standard solution for it.
    I also developed report in rdf fromat , But it did not create restriction on printed checks.

    Dear...
    Can you please confirm ...if you are using the standard report or developing the custom rdf...
    I would suggest you to use BI publisher to develop your custom report.
    Well, you can use your custom developed rdf and designed the Report template using MS-Word ie. RTF file....the same process we follow for Bi Publisher report development.
    Also I can suggest you to follow the link below to fix the number of Invoices to 3 or more as per your per page requirement.
    Please check the below link and also you can find solution for your problem here for sure.
    http://blogs.oracle.com/xmlpublisher/2007/11/check_print_template.html
    http://blogs.oracle.com/xmlpublisher/2009/03/new_10134_patch.html
    http://blogs.oracle.com/xmlpublisher/2007/11/11i_check_print_support_patch.html
    Thanks
    Ratnesh

  • How to call the print method from a custom program

    Hi,
        I need to print the text thats displayed in a custom area. Its added to a custom container. Can anyone help me out to do this?
    Thanks
    Lilan

    Hi
    U should create an abap list and print it, so a possible code could be:
    * Leave the MODULE POOL
    LEAVE TO LIST-PROCESSING AND RETURN TO SCREEN <SCREEN>.
    * Create a new page to be printed immediataly
    NEW-PAGE PRINT ON.
    * Create the list
    WRITE: 'TEXT'.
    * Back to MODULE POOL
    LEAVE LIST-PROCESSING.
    Try and let's know the result
    Max

  • Default display or print methods

    Hello All,
    Is there a default method that is called to display a user defined type instance? For example, lets say there is a type myType. If I use the following SQL:
    select myType from myTypeTable;
    Is there a method that is called for myType to format it? In other words, does Oracle have an equivalent to Java's toString() method?

    You can add a title to your worksheet and include the conditions used in the report.
    Add title:
    From edit worksheet view-> options button -> table tab: check Title.
    To add conditions to printout of report...I think
    from report view double click title -> text tab: click insert button - select conditions
    CC

  • What are the dimensions, material, colors, print method used to make the collateral box used as a cover for Apple products?

    Production management students are continuously working towards improving your survey experience. I've been assigned a project from my professor that requires me to identify: Materials, Color/Ink used to produce a product.
    What types of Materials are used in box for your product?
        iPhone 4 cover box                                                 iPhone 5s cover box                                        iPhone 6 cover box
    What colors were used for the dye stamps or to include text unto boxes?
    What Ink/paper was used on the boxes or paper?
    Startup tutorial paper                                              Apple sticker logo paper

    This is a user-to-user forum, so they won't answer you here.

  • Print out all methods in program with print statements

    Does anyone know how I would be able to print out all the methods in a program. For example:
    class bd220p1 {
         public static void main(String args[])  {
              int lightspeedi,lightspeedm;
              long days;
              long seconds;
              long distancei;
              long distancem;
              // approximate speed of light in miles per second
              lightspeedi = 186000;
                // approximate speed of light in Kilometers per second
              lightspeedm = 300000;
              days = 1000; // specify number of days here
              seconds = days * 24 * 60 * 60; // convert to seconds
              distancem = lightspeedm * seconds; // compute distance in English system
              distancei = lightspeedi * seconds;// compute distance in Metric system
              System.out.print("In " + days);
              System.out.print(" days light will travel about ");
              System.out.println(distancei + " miles and");
              System.out.print(distancem + " Kilometers ");
    }This code would produce 5 print statements for the 4 methods:
    1 Main method
    2 Print method
    3 Print method
    4 Println method
    5 Print method
    Does anyone know I can write the could to accomplish this? Right now I am experimenting with try/catch statements. Any help is greatly appreciated.

    It seems to me the easiest approaches (other than using a tool someone else has already written) are:
    1) Compile the source, and then use BCEL
    2) Try some regular expressions; it won't be perfect but maybe you can tweak it until it's good enough.
    3) Parse the source, and examine the parse tree.
    1 and 3 will give you much better results, but require you to use outside libraries (or write a parser yourself).
    You can do 2 using standard stuff from the JDK, but you may spend a lot of trial-and-error gettng the regexps right.
    Which you choose will depend a lot on what the prof giving the assignment allows.
    Also he may have some particular kind of solution in mind -- did he say anything?
    If you're not sure what to do, ask your prof for clarification.

Maybe you are looking for

  • Pictures taked with Camera are not saved.

    When taking pictures using my iPad Air the app functions normally but the pictures are not saved to the iPad.  Am I missing a setting somewhere in Settings?

  • Special liability in credit management

    I have many customers who have "Special Liability" bucket filled in their credit master.  This "special liability" is actually bills of exchange.  I would like to know how to remove this amount from the calculation of the "credit exposure".  In other

  • Leopard 10.5.6 bluetooth and sync MobileMe don't works

    After 10.5.6 bluetooth icone is disappeared and now I can't sent in sleep my MacBook. I try to remove battery and keep for 5 seconds shut down button but don't work again. Push Sync for MobileMe don't work with my iPhone from iCal and Address Book. O

  • PHP help for a Novice please

    Hi, I am learning php, because I am working on a site that uses it, so, there is some syntax which I don't understand its function, so I thought if I post it here somebody may be able to tell me what it would do..... A page has a form on it, the form

  • Can't start apple mobile device service

    I downloaded the latest itunes version onto a Windows 7 computer and now I can't start the apple mobile device service.  Why is that?