How to check if a file is completely written?

Hi
My question relates to polling for a file in a particular directory written by an external process (maybe FTP ...). What I need to know is whether there is a way of determining whether the file has been completely written to the disk by the external process.
I need to find a way so that I do not end up processing partial files in the polling process.
Thanks
Raghu Warrier

My question relates to polling for a file in a
particular directory written by an external processNot particularly, one can implement some type of lock file or even maybe some OS-specific locking mechanisms, but none of which which one would enable/control from within Java. One simple method to dramatically reduce contention time in this manner for most OSs (and to emprically introduce some level of atomicity) is to write to a separate directory on the same filesystem, then once the other process knows the file is complete, then move it to the new directory which generally involved just index pointer addition/moving into the directory entry which is of course much more `atomic' than polling on directory entries themselves.
is a way of determining whether the file has been
completely written to the disk by the external
process. Some OSs don't write the file size until the writing process is done, but this is not guaranteed across OSs. Anyway to introduce a socket semaphore?
I need to find a way so that I do not end up
processing partial files in the polling process.You can also poll the filename->size mappings and with a sufficient poll delta determine if the file is no longer being written. This is not perfect, but a fail-foul solution at that.

Similar Messages

  • How to check if a file is complete?

    Hi all,
    My problem is simple. I want to make sure that the file I am about to FTP from remote server to a local server (thru java) is complete. The file (lets call it TESTFILE.001) is sent by the client ( not at fixed time) few times a day. My process runs every hour and grabs this file if it exists. If no file is found then process just terminates. But I dont want to grab it if its still being populated. How do I do this?
    I cannot setup a file object for this file as I only have FTP login for the remote server.
    Thanks in advance.
    -Chirag

    Hi all,
    Since I was trying to access the file on remote server, there is no way in java to set up a direct File object. (It works on windows machine to windows but not with Unix)
    The way I finally did it was by using ftp. As a rule, when a file is being written to, it is locked and reports size 0.
    So I check if file size is zero. If it is then I know that either there is no file or the file is currently being written to (hence not complete)

  • How to check & unzip zip file using java

    Dear friends
    How to check & unzip zip file using java, I have some files which are pkzip or some other zip I want to find out the type of ZIp & then I want to unzip these files, pls guide me
    thanks

    How to check & unzip zip file using java, I have
    ve some files which are pkzip or some other zip I
    want to find out the type of ZIp & then I want to
    unzip these files, pls guide meWhat do you mean "other zip"? Either they're zip archives or not, there are no different types.

  • How to check Whether the File is in Progress or used by some other resource

    Hi All,
    I am retrieving a file from the FTP server using Apache commons FTP.
    I need to check whether the file is fully retrieved or in progress.
    for now i can able to use the file which is partially retrieved. it is not throwing any file sharing exception or i am unable to find whether it is in progress.
    How to check whether the file is in progress ? or The file is accessed by some other resource ?
    Pls Help me.
    Thanks,
    J.Kathir

    Hi Vamsi,
    Explicitly such kind of requirement has not been catered and i dont think you would face a problem because any application that is writing to a file will open the file in the read only mode to any other simultaneous applications so i think your concerns although valid are already taken care off .
    In the remote case you still face a problem then as a work around. Tell the FTP administrator to set the property to maximum connections that can be made to ftp as one. I wonder if you have heard of the concept of FTP handle , basically the above workaround is based on that concept itself. This way only one application will be able to write.
    The file adapter will wait for its turn and then write the files.
    Regards
    joel
    Edited by: joel trinidade on Jun 26, 2009 11:06 AM

  • JavaScript: How to check if a file exists.

    Hello Everybody,
    Can you tell me how to check if a file exists using JavaScript and Internet Explorer.
    Browsing on this website I could read about the command "f.exists()" and it was necessary to include "java.io.*".
    Should I use this same command and should I include the same files? Or are there other files and other commands?
    Thanks in advance.

    sorry ya. there is no command to check whether a file exists using javascript. The following code says the object name and value. But it can't say whether the file exists in the harddisk or .. Javascript cannot access database and system resources. If the file exists or not can be checked through the application (ASP, CFML, ..) you are using.

  • How to check whether a file exist in the program folder or not?

    Hi guys,
    how to check whether a file exist in the program folder or not? Let is say i recieve a file name from user then i want to know if the file is there not and act on that base.
    abdul

    Look at the class java.io.File and the .exists() method:
    http://java.sun.com/j2se/1.4/docs/api/java/io/File.html

  • How conform that a receiving file is completly received.

    i am sending a file.
    how conform that a receiving file is completly received?

    server code
    package server;
    import java.beans.XMLEncoder;
    import java.io.*;
    import java.net.*;
    import java.nio.channels.FileLock;
    import java.sql.ResultSet;
    import java.util.ArrayList;
    public class Server2 {
        public static void main(String args[]) {
            int port = 6789;
            Server2 server = new Server2(port);
            server.startServer();
        // declare a server socket and a client socket for the server;
        // declare the number of connections
        ServerSocket echoServer = null;
        Socket clientSocket = null;
        int numConnections = 0;
        int port;
        public Server2(int port) {
            this.port = port;
        public void stopServer() {
            System.out.println("Server cleaning up.");
            System.exit(0);
        public void startServer() {
            // Try to open a server socket on the given port
            // Note that we can't choose a port less than 1024 if we are not
            // privileged users (root)
            try {
                echoServer = new ServerSocket(port);
            } catch (IOException e) {
                System.out.println(e);
            System.out.println("Server is started and is waiting for connections.");
            System.out.println("With multi-threading, multiple connections are allowed.");
            System.out.println("Any client can send -1 to stop the server.");
            // Whenever a connection is received, start a new thread to process the connection
            // and wait for the next connection.
            while (true) {
                try {
                    clientSocket = echoServer.accept();
                    numConnections++;
                    Server2Connection oneconnection = new Server2Connection(clientSocket, numConnections, this);
                    new Thread(oneconnection).start();
                } catch (IOException e) {
                    System.out.println(e);
    class Server2Connection implements Runnable {
        //BufferedReader is;
        ObjectInputStream is;
        ObjectOutputStream os;
        XMLEncoder xml;
        Socket clientSocket;
        String numConn;
        int id;
        Server2 server;
    FileLock fl ;
        public Server2Connection(Socket clientSocket, int id, Server2 server) {
            this.clientSocket = clientSocket;
            this.id = id;
            this.server = server;
            numConn = "Connection " + id + " established with: " + clientSocket;
            System.out.println("Connection " + id + " established with: " + clientSocket);
            try {
                is = new ObjectInputStream(clientSocket.getInputStream());
                os = new ObjectOutputStream(clientSocket.getOutputStream());
                //xml = new XMLEncoder(new BufferedOutputStream( new FileOutputStream("first.xml")));
              //  xml = new XMLEncoder(new BufferedOutputStream( new FileOutputStream("first.xml")));
                FileOutputStream fs = new FileOutputStream("first.xml");
                BufferedOutputStream br = new BufferedOutputStream(fs);
                xml = new XMLEncoder(br);
                //fl =  fs.getChannel().lock();
            } catch (IOException e) {
                System.out.println(e);
        public void run() {
            Object line;
            try {
                boolean serverStop = false;
                int n = 0;
                while (true) {
                    line = is.readObject();
                    if (line instanceof String) {
                        String s = (String) line;
                        System.out.println("In Server :: The input is " + s);
                        UserData ud = new UserData();
                        ud.setAdd("karachi");
                        ud.setId("123");
                        ud.setName("XML testing..");
                        System.out.println("Tring to lock locked..");
                        fl.channel().tryLock();
                        System.out.println("File locked..");
                        xml.writeObject(ud);
                        xml.flush();
                        //os.writeObject(ud);
                        n = Integer.parseInt(s);
                    if (n == -1) {
                        serverStop = true;
                        break;
                    if (n == 0) {
                        break;
                //  System.out.println("Connection " + id + " closed.");
                fl.release();
                is.close();
                os.close();
                xml.close();
                clientSocket.close();
                if (serverStop) {
                    server.stopServer();
            } catch (Exception e) {
                System.out.println("Exception..." + e);
    client code
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    package scoket1;
    import java.beans.XMLDecoder;
    import server.UserData;
    //import server.MyRS;
    import java.io.*;
    import java.net.*;
    import java.sql.ResultSet;
    import java.util.ArrayList;
    import javax.swing.JOptionPane;
    public class Client {
        public static void main(String[] args) {
            String hostname = "localhost";
            int port = 6789;
            // declaration section:
            // clientSocket: our client socket
            // os: output stream
            // is: input stream
            Socket clientSocket = null;
            ObjectOutputStream os = null;
            ObjectInputStream is = null;
            XMLDecoder de = null;
            // Initialization section:
            // Try to open a socket on the given port
            // Try to open input and output streams
            try {
                clientSocket = new Socket(hostname, port);
                os = new ObjectOutputStream(clientSocket.getOutputStream());
                is = new ObjectInputStream(clientSocket.getInputStream());
                de = new XMLDecoder(new BufferedInputStream(new FileInputStream("first.xml")));
            } catch (UnknownHostException e) {
                System.err.println("Don't know about host: " + hostname);
            } catch (IOException e) {
                System.err.println("Couldn't get I/O for the connection to: " + hostname);
            // If everything has been initialized then we want to write some data
            // to the socket we have opened a connection to on the given port
            if (clientSocket == null || os == null || is == null) {
                System.err.println("Something is wrong. One variable is null.");
                return;
            try {
                while (true) {
                    System.out.print("Enter an integer (0 to stop connection, -1 to stop server): ");
                    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
                    String keyboardInput = br.readLine();
                    os.writeObject(keyboardInput);
                    int n = Integer.parseInt(keyboardInput);
                    if (n == 0 || n == -1) {
                        break;
    //                Object responseObj = null;
    //                responseObj = is.readObject();
                    Object test = null;
                    test = (Object) de.readObject();
                    if (test instanceof String) {
                        String msg = (String) test;
                        System.out.println(msg);
                    } else if (test instanceof UserData) {
                        System.out.println("XML File Test succesful .. be happy ..");
                        System.out.println("Array of User Data ..");
                        UserData ud = (UserData) test;
                        System.out.println("Name:-    " + ud.getName());
                        System.out.println("ID :-     " + ud.getId());
                        System.out.println("Address:- " + ud.getAdd());
                // clean up:
                // close the output stream
                // close the input stream
                // close the socket
                os.close();
                is.close();
                clientSocket.close();
            } catch (UnknownHostException e) {
                System.err.println("Trying to connect to unknown host: " + e);
            } catch (Exception e) {
                System.err.println("Exception:  " + e);
    }

  • How to check-in multiple files with same name having different revision num

    Hi
    Can anyone please tell me, how to check-in multiple files with the same name with different revision number using RIDC API.
    For eg:
    First I will check-in a file(TestFile.txt) into a content server with revision number 1 using RIDC API in ADF application. Then after some time, will modify the same file(TestFile.txt) and check-in again. I tried to check-in same file multiple times, however first time its checking-in correctly into server showing revision as 1, while checking-in same file again, its not giving any errror message, and also its not reflecting in server. Only one file(TestFile.txt) is reflecting in server.
    How to implement this functinality using RIDC API? Any suggestions would be helpful.
    Regards
    Raj
    Edited by: 887680 on Mar 6, 2013 10:48 AM

    Hi Srinath
    Thanks for your response. Its not cloning, its like check-in file first, then check-out the file and do some editing and then again upload the same file with different revision number using RIDC. I got the solution now.
    Regards
    Raj

  • How to convert a pdf file with hand-written signature?

    How to convert a pdf file with hand-written signature?

    Hi Lotus1215,
    Once the document is signed we cannot edit that document, hence convertion is not possible
    Please see the article mentioned below
    http://forums.adobe.com/docs/DOC-1515
    Let me know if you have any other question.
    Regards,
    ~Pranav

  • How do I recover a file what was written in the 'notes' app that I have accidentally deleted?

    how do I recover a file what was written in the 'notes' app that I have accidentally deleted?

    If you have an iTunes backup or iCloud backup containing that note you can restore from that backup.
    If you have no backups the note is gone.

  • File adapter - how to make shure a file is complete for sender/receiver?

    Hi everybody,
    I want to use the file adapter and a question arises for both sender and
    receiver:
    On the sender: How does the PI know when a file is complete for reading?
    Can this be a problem (PI starts reading the file when it is not complete?)
    On the receiver: How does the receiver know when a file written by
    PI is complete? Does PI support some kind of write to tmpfile then rename
    schema?
    Thanks for any suggestions
    Best regards
    Stefan

    Hi Stefan,
    On the sender: How does the PI know when a file is complete for reading?
    Can this be a problem (PI starts reading the file when it is not complete?)
    Yes, it could be a problem: Have a look at below from help.sap
    Advanced Mode
    To specify additional parameters in the adapter configuration, set the Advanced Modeindicator.
    ●      Msecs to Wait Before Modification Check
    Enter the number of milliseconds that the adapter must wait before it checks whether the files have been changed.
    This parameter is not available if you have selected File Content Conversion as the Message Protocoland then made an entry under Recordsets per Message that splits an input file into several messages.
    This parameter is applicable only for the File adapter. If you enter a value in this field when configuring the sender FTP adapter, it will have no effect.
    Regards,
    Carlos

  • How to check whether a file is present in the UNIX directory of app. server

    Hi,
            I am creating files in the UNIX directory in the application server using :
                       CONCATENATE '/sapmnt/RD1/interfaces/client670/'
                       p_fname '.CSV' INTO w_filename.
               OPEN DATASET w_filename FOR OUTPUT IN TEXT MODE.
              LOOP AT t_output1.
                      TRANSFER t_output1 TO w_filename.
              ENDLOOP.
             CLOSE DATASET w_filename.
    I am unable to check whether a file with the same name exists or not. How to check the duplicate state of the file.

    You can use the following fm
    RZL_READ_FILE
    or
    use OPEN DATASET FOR INPUT.

  • How to check if a file is being read by another program?

    Hey all,
    I just have a few question for a project I am doing:
    How do I check if a file is being read by another program?
    How do I check how many lines it read?
    How do I get Keyboard input from the user when he is using another program other than mine? Ex: Pressing Ctrl-G to take a screenshot.
    How can I halt another program from reading a file when it already opened it? Ex: The other program opened a file and began reading. Now it is at line 2 and I want to make it skip 10 lines and contontinue.
    Thanks,
    Bluelikeu

    How do I check if a file is being read by another
    program?This is about the only partially sensible question you asked. But the answer is that unless you use some native code, you can't.
    How do I check how many lines it read?It doesn't even make sense to ask this question. First of all, what's a "line" anyway? Files are just sequences of bytes. A "line" is only in the interpretation of those bytes, such as if it contains <cr><lf> sequences an application may choose to render the contents of those bytes as logical "lines" of string sequences. Second of all, why the heck would it matter to you how many bytes have already been read by some other process(es)?
    How do I get Keyboard input from the user when he is
    using another program other than mine? Ex: Pressing
    Ctrl-G to take a screenshot.You want to spy on other applications? Shame on you, Mr. Spyware creator.
    How can I halt another program from reading a file
    when it already opened it? Ex: The other program
    opened a file and began reading. Now it is at line 2
    and I want to make it skip 10 lines and contontinue.Shame on you Mr. Spyware creator.

  • How to check In a file with folder structure

    Hi,
    Is it possible to check in "a file with its complete folder structure".
    For Ex: folder A contains Folder B and B contains a file , Then is there an option to check in the file in content server with the same structure A-->B-->file.
    Thanks In advance.

    JRS, this will copy ALL the files and folders from folder A to the content server.
    If he only wants to copy file A that is inside folder B than your way is somewhat overkill unless you are sure that the file is the only one in the complete structure but that i doubt...
    I haven't checked it before but perhaps someone can tell if this is possible...
    If you check in a file, perhpas you can get the original file and foldername from the metadata. If this is possible, you can create your own code that hooks on the check in and then create a directory or just move the file in the directory.
    I have written such a component but it's based on some custom metadata we use, not on the original filename.
    If i find the time, i will try some things and tell you if it works

  • How to check if the file already exists in the client directory

    Hi all.
    I'm on devsuite 10g. I'm using webutil to download files from DB using webutil function db_to_client.
    What I need is to check if the file already exists in the client directory and if yes to display a message to ask the user if he wants to overwrite or no. How can I make this???
    Here is the code that I'm using to download the file.
    Thanks all for the collaboration.
    Fabrizio
    declare
    file_path varchar2(2000) := null;
    BEGIN
    /** I ask where saving the file on the client machine **/
    file_path:= webutil_file.file_selection_dialog
    (directory_name => null,
    file_name => :bin_docs.name,
    file_filter => '',
    title => 'Saving file',
    dialog_type => save_file, --save_file
    select_file => TRUE);
    /** I download the file from DB to client **/
    if webutil_file_transfer.DB_To_Client_With_Progress
    ( file_path ,
    'BIN_DOCS',
    'DOC' ,
    'doc_id = '||:bin_docs.doc_id,
    'Downloading file',
    ' '||:bin_docs.name) then
    msg_alert('Download del file avvenuto con successo','I',false);
    else
    msg_alert('Si è verificato il seguente errore in fase di download '||SQLERRM,'I',false);
    end if;
    end;

    How about something like the below:
    Note: I have a yes/no alert to asking if they want to over-write the existing file.
    DECLARE
    file_path VARCHAR2(2000) := null;
    over_write BOOLEAN := TRUE;
    BEGIN
    /** I ask where saving the file on the client machine **/
    file_path:= webutil_file.file_selection_dialog
    (directory_name => null,
    file_name => :bin_docs.name,
    file_filter => '',
    title => 'Saving file',
    dialog_type => save_file, --save_file
    select_file => TRUE);
    IF webutil.file_exists(file_path) THEN
    /** check a file by the same name exists in the selected directory **/
    IF show_alert('Ask_overright') != alert_button1 THEN
    /** If we say no then set over_write value to false **/
    over_write := FALSE;
    END IF;
    END IF;
    IF over_write THEN
    /** I download the file from DB to client **/
    IF webutil_file_transfer.DB_To_Client_With_Progress
    ( file_path ,
    'BIN_DOCS',
    'DOC' ,
    'doc_id = '||:bin_docs.doc_id,
    'Downloading file',
    ' '||:bin_docs.name) then
    msg_alert('Download del file avvenuto con successo','I',false);
    ELSE
    msg_alert('Si è verificato il seguente errore in fase di'
    ||' download '||SQLERRM,'I',false);
    END IF
    END IF;
    END;
    cheers
    Q

Maybe you are looking for

  • Reg : Exporting BLOB data to EXCEL

    Hi , I have a requirement of exporting BLOB data to EXCEL. I tried it but i ma facing issue. Can anyone suggest me how to do it. Thanks & Regards : Pramila Padam

  • 10 customer and 10 employed sales

    Hi experts, I would like sorting 1. consumer sales and 2. employed sales only for the 10 best every day how to make a query, because the existing Query Engadget incompatible with the existing results on the sales analysis SELECT top 10 T0.Cardcode,ma

  • Lost on application.cfc

    Hi all, I've used application.cfm for ages on our site (now in sustainment) and we have been moved to a new server using CF9. Our server dudes have "per application" settings in place where I can map my custom tag directory (works fine) but when I us

  • How do i delete a photo that is stuck in red eye reduction of the photos app?

    I have a photo in the Photos App that is stuck in the Edit Feature. I had accidentally pushed the Red-Eye reduction and it cannot detect any red-eyes.

  • Updating MDM table when another table gets updated

    Hi Guys, We use MDM catalog for SRM we have a table Catogories and Hierarchy, Our requirement is when ever Catogories table gets updated we have to update the Hierarchy table using some logic, So please let me know whether it is possible to do this a