Results 1 to 2 of 2
  1. #1
    IYIaster is offline Member
    Join Date
    Jul 2009
    Rep Power

    Default trying to print a text file.

    I'm working on a txt file that I want to print.

    Java Code:
     FileInputStream textStream;
                textStream = new FileInputStream("C://mew.txt");
                DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
                Doc mydoc = new SimpleDoc(textStream, flavor, null);
                PrintService[] services = PrintServiceLookup.lookupPrintServices(flavor, aset);
                PrintService defaultService = PrintServiceLookup.lookupDefaultPrintService();
                if (services.length == 0) {
                    if (defaultService == null) {
                        //no printer found
                    } else {
                        //print using default
                        DocPrintJob job = defaultService.createPrintJob();
                        job.print(mydoc, aset);
                } else {
                    //built in UI for printing you may not use this
                    PrintService service = ServiceUI.printDialog(null, 200, 200, services, defaultService, flavor, aset);
                    if (service != null) {
                        DocPrintJob job = service.createPrintJob();
                        job.print(mydoc, aset);
            } catch (FileNotFoundException ex) {
                Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex);
    For some reason all of the "aset" are underlined and say: "lookupPrintServices(javax.print.DocFlavor,javax.p rint.attribute.AttributeSet) in javax.print.PrintServiceLookup cannot be applied to (javax.print.DocFlavor,aset)"

    Also when I run the program I get this error:

    Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: Uncompilable source code
    at my.NewJFrame.NewJFrame.jButton1ActionPerformed(New
    at my.NewJFrame.NewJFrame.access$2400( 38)
    at my.NewJFrame.NewJFrame$24.actionPerformed(NewJFram
    at javax.swing.AbstractButton.fireActionPerformed(Abs
    at javax.swing.AbstractButton$Handler.actionPerformed (
    at javax.swing.DefaultButtonModel.fireActionPerformed (
    at javax.swing.DefaultButtonModel.setPressed(DefaultB
    at javax.swing.plaf.basic.BasicButtonListener.mouseRe leased(
    at java.awt.Component.processMouseEvent(Component.jav a:5501)
    at javax.swing.JComponent.processMouseEvent(JComponen
    at java.awt.Component.processEvent( 6)
    at java.awt.Container.processEvent( 6)
    at java.awt.Component.dispatchEventImpl(Component.jav a:3968)
    at java.awt.Container.dispatchEventImpl(Container.jav a:2024)
    at java.awt.Component.dispatchEvent( 03)
    at java.awt.LightweightDispatcher.retargetMouseEvent(
    at java.awt.LightweightDispatcher.processMouseEvent(C
    at java.awt.LightweightDispatcher.dispatchEvent(Conta
    at java.awt.Container.dispatchEventImpl(Container.jav a:2010)
    at java.awt.Window.dispatchEventImpl( )
    at java.awt.Component.dispatchEvent( 03)
    at java.awt.EventQueue.dispatchEvent( 463)
    at java.awt.EventDispatchThread.pumpOneEventForHierar chy(
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(
    at java.awt.EventDispatchThread.pumpEvents(EventDispa
    at java.awt.EventDispatchThread.pumpEvents(EventDispa
    BUILD SUCCESSFUL (total time: 14 seconds)

    This is my first time trying to print something Thanks for any help.

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Rep Power


    You have to compile the source code before attempting to run it.
    Read the API specs for the lookupPrintServices method to see the parameters that it expects and compare them with what you are passing it.

Similar Threads

  1. How to print text file in java(dotmatrix printer)
    By yoganeethi in forum Advanced Java
    Replies: 4
    Last Post: 12-01-2010, 02:45 PM
  2. Print .prn file using java
    By nishant in forum Advanced Java
    Replies: 0
    Last Post: 07-14-2009, 09:15 AM
  3. Replies: 6
    Last Post: 04-09-2009, 02:11 AM
  4. Print the text file and print preview them
    By Java Tip in forum java.awt
    Replies: 0
    Last Post: 06-22-2008, 11:04 PM
  5. Print a picture file
    By oli001 in forum New To Java
    Replies: 0
    Last Post: 11-26-2007, 02:40 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