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 51507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T16:45:40+00:00 2026-05-10T16:45:40+00:00

I have a Java application that monitors a folder for incoming XML files. When

  • 0

I have a Java application that monitors a folder for incoming XML files. When a new file is detected I need to test the file that it is not currently being updated and is closed. My thought is to use File.canWrite() to test this. Is there any issue with doing this? Is this a good way to test that a file has been completely written?

Other ideas I am throwing around are:

  • Parse the incoming XML file and test that the closing tag is there.
  • Check for the EoF character.

I just am not sure that any of these methods will handle all scenarios.

  • 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. 2026-05-10T16:45:41+00:00Added an answer on May 10, 2026 at 4:45 pm

    No, canWrite is not suitable for this purpose. In general the file will be writable even if another process is writing.

    You need a higher level protocol to coordinate the locking. If you plan to use this code on a single platform, you may be able to use NIO’s FileLock facility. But read the documentation carefully, and note that on many platforms, the lock is only advisory.

    Another approach is to have one process write the file with a name that your process won’t recognize, then rename the file to a recognizable name when the write is complete. On most platforms, the rename operation is atomic if the source and destination are the same file system volume. The name change might use a different file extension, or even moving the file from one directory to another (on the same volume).

    Since in this case you are working exclusively with XML, looking for a close tag would work, but it isn’t foolproof—what if there are comments after the final markup, or the writer or simply doesn’t write valid XML?

    Looking for the EOF will not work. There will always be an EOF, even when the writer has just opened the file and hasn’t written anything yet. If this weren’t so, the easiest thing would be to allow the reader to start parsing as soon as the file showed up; it would simply block until the writer closed the file. But the file system doesn’t work this way. Every file has an end, even if some process is currently moving it.

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

Sidebar

Ask A Question

Stats

  • Questions 63k
  • Answers 63k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer Firstly, processors do a single set of micro instructions per… May 11, 2026 at 10:34 am
  • added an answer Use the this keyword to get intellisense access to the… May 11, 2026 at 10:34 am
  • added an answer Hey there, thought I'd give you some insight in to… May 11, 2026 at 10:34 am

Related Questions

I have a Java application that monitors a folder for incoming XML files. When
I have a Java application that launches another java application. The launcher has a
I have a Java application that's very String-heavy - it takes a feed of
I have a java application that has Web Services published using Axis. With the
I have a java application that is connected to a view on a remote
I have inherited a Java application (servlets) that runs under Tomcat. For historical reasons,
I have a paint application that runs as a Java applet. I need to
I have a Java swing application with a panel that contains three JComboBoxe s
At a new job I started, we have both a Java application that handles
i have a server - client application that runs on java 1.3; i want

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.