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

  • Home
  • SEARCH
  • 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 6675349
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:50:41+00:00 2026-05-26T03:50:41+00:00

How do I know if a software is done writing a file if I

  • 0

How do I know if a software is done writing a file if I am executing that software from java?For example, I am executing geniatagger.exe with an input file RawText that will produce an output file TAGGEDTEXT.txt. When geniatagger.exe is finished writing the TAGGEDTEXT.txt file, I can do some other staffs with this file. The problem is- how can I know that geniatagger is finished writing the text file?

try{
  Runtime rt = Runtime.getRuntime();
    Process p = rt.exec("geniatagger.exe -i "+ RawText+ " -o TAGGEDTEXT.txt");
  }
  • 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-26T03:50:41+00:00Added an answer on May 26, 2026 at 3:50 am

    You can’t, or at least not reliably.

    In this particular case your best bet is to watch the Process complete.

    You get the process’ return code as a bonus, this could tell you if an error occurred.

    If you are actually talking about this GENIA tagger, below is a practical example which demonstrates various topics (see explanation about numbered comments beneath the code). The code was tested with v1.0 for Linux and demonstrates how to safely run a process which expects both input and output stream piping to work correctly.

    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.util.concurrent.Callable;
    
    import org.apache.commons.io.IOUtils;
    
    public class GeniaTagger {
    
        /**
         * @param args
         */
        public static void main(String[] args) {
            tagFile(new File("inputText.txt"), new File("outputText.txt"));
        }
    
        public static void tagFile(File input, File output) {
            FileInputStream ifs = null;
            FileOutputStream ofs = null;
            try {
                ifs = new FileInputStream(input);
                ofs = new FileOutputStream(output);
                final FileInputStream ifsRef = ifs;
                final FileOutputStream ofsRef = ofs;
    
                // {1}    
                ProcessBuilder pb = new ProcessBuilder("geniatagger.exe");
                final Process pr = pb.start();
    
                // {2}
                runInThread(new Callable<Void>() {
                    public Void call() throws Exception {
                        IOUtils.copy(ifsRef, pr.getOutputStream());
                        IOUtils.closeQuietly(pr.getOutputStream());   // {3}
                        return null;
                    }
                });
                runInThread(new Callable<Void>() {
                    public Void call() throws Exception {
                        IOUtils.copy(pr.getInputStream(), ofsRef);   // {4}
                        return null;
                    }
                });
                runInThread(new Callable<Void>() {
                    public Void call() throws Exception {
                        IOUtils.copy(pr.getErrorStream(), System.err);
                        return null;
                    }
                });
    
                // {5}
                pr.waitFor();
                // output file is written at this point.
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                // {6}
                IOUtils.closeQuietly(ifs);
                IOUtils.closeQuietly(ofs);
            }
        }
    
        public static void runInThread(final Callable<?> c) {
            new Thread() {
                public void run() {
                    try {
                        c.call();
                    } catch (Exception e) {
                        e.printStackTrace();
                    } finally {
                    }
                }
            }.start();
        }
    }
    
    1. Use a ProcessBuilder to start your process, it has a better interface than plain-old Runtime.getRuntime().exec(...).

    2. Set up stream piping in different threads, otherwhise the waitFor() call in ({5}) might never complete.

    3. Note that I piped a FileInputStream to the process. According to the afore-mentioned GENIA page, this command expects actual input instead of a -i parameter. The OutputStream which connects to the process must be closed, otherwhise the program will keep running!

    4. Copy the result of the process to a FileOutputStream, the result file your are waiting for.

    5. Let the main thread wait until the process completes.

    6. Clean up all streams.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone know of any software that can be used to create Agile User
I was wondering if you guys know of any software that allows me to
Has anyone done something like this? How? I'm just starting a project that will
I start university in a few weeks (software engineering degree) and know that one
I currently use Ant to build Java software. However, all development that I have
Do you know of software which is capable of emulating networking conditions such as
Does anyone know how software fault tolerance is implemented in Air Traffic Control Systems?
Do you know of software like MS Visual Studio for Mac ?
do you know any software similar to NDepend? I've got it just recently, and
Does anyone know of existing software or algorithms to calculate a package size for

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.