Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1062549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:38:41+00:00 2026-05-16T18:38:41+00:00

OK I have a program that: Creates a temporary file based on a users

  • 0

OK I have a program that:

  1. Creates a temporary file based on a
    users input
  2. Prints the File(Optional)
  3. Deletes the File (Optional)

My problem sits between stages 2&3, I need to wait for the file to finish printing until I can delete it.

FYI: the printing will take 5-10 minutes (large file to spool on an old computer)

So I need to from Java be able to to check if:

  • the defualt print queue is empty

  • the file is in use (note: File.canWrite() returns true, when printing)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T18:38:42+00:00Added an answer on May 16, 2026 at 6:38 pm

    Have you checked the Java Print API? From http://download.oracle.com/javase/1.4.2/docs/api/javax/print/event/PrintJobListener.html:

    public interface

    PrintJobListener

    Implementations of this listener
    interface should be attached to a
    DocPrintJob to monitor the status of
    the printer job.

    I imagine you can submit a print job and then monitor its status through this.

    There’s also a fairly complete example at exampledepot.com/egs/javax.print/WaitForDone.html: (Note: URL seems to have changed, and points to potential malware)

    try {
        // Open the image file
        InputStream is = new BufferedInputStream(
            new FileInputStream("filename.gif"));
        // Create the print job
        DocPrintJob job = service.createPrintJob();
        Doc doc = new SimpleDoc(is, flavor, null);
    
        // Monitor print job events
        PrintJobWatcher pjDone = new PrintJobWatcher(job);
    
        // Print it
        job.print(doc, null);
    
        // Wait for the print job to be done
        pjDone.waitForDone();
    
        // It is now safe to close the input stream
        is.close();
    } catch (PrintException e) {
    } catch (IOException e) {
    }
    
    class PrintJobWatcher {
        // true iff it is safe to close the print job's input stream
        boolean done = false;
    
        PrintJobWatcher(DocPrintJob job) {
            // Add a listener to the print job
            job.addPrintJobListener(new PrintJobAdapter() {
                public void printJobCanceled(PrintJobEvent pje) {
                    allDone();
                }
                public void printJobCompleted(PrintJobEvent pje) {
                    allDone();
                }
                public void printJobFailed(PrintJobEvent pje) {
                    allDone();
                }
                public void printJobNoMoreEvents(PrintJobEvent pje) {
                    allDone();
                }
                void allDone() {
                    synchronized (PrintJobWatcher.this) {
                        done = true;
                        PrintJobWatcher.this.notify();
                    }
                }
            });
        }
        public synchronized void waitForDone() {
            try {
                while (!done) {
                    wait();
                }
            } catch (InterruptedException e) {
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a program that creates a small file in the Bin directory for
I'm experimenting with file I/O. I have a small practice program that creates a
I have a simple java program that creates a series of temporary files stored
I have a program that creates multiple text files of rdf triples. I need
I have a program that creates a JFrame and makes it visible. Is there
I have a program that creates semaphore. But when i try to use SETALL,
Greetings I have a program that creates multiples instances of a class, runs the
I have a simple program that creates a thread, loops twenty times and then
I have a Delphi program that creates HTML files. Later when a button is
I have a program that starts up and creates an in-memory data model and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.