Results 1 to 6 of 6

Thread: Program to see file used by another process

  1. #1
    Join Date
    Dec 2009
    Posts
    296

    Program to see file used by another process

    Hello,
    I would like to test if a file is used by another process.
    I try to do the following code, have a look at it
    Code:
    canRead() and canWrite()
    but it returns true even if the file is opened. Do you have a similar program that is the source code of it. If you have such a code or have any idea of how to do it then please let me know I am the interested one here. Thanks in advance.

  2. #2
    Join Date
    Nov 2009
    Posts
    343

    Re: Program to see file used by another process

    Hello,
    With the File class, you can not. What you can do is create a FileInputStream or FileOutputStream, and do a close (). I recommend you to use a try / catch around, and if an exception is thrown, it's that close () failed, so your file is used for reading or writing. I think you should first have any idea of the java.io package that contains all the input and the output classes which are used in the I/O programs in java. So, I strongly recommend you to first learn or take a look at the java.io package.

  3. #3
    Join Date
    Nov 2009
    Posts
    356

    Re: Program to see file used by another process

    Hello,
    Attention because it can be dangerous. Even if you write anything in it, simply open a FileOutputStream erase the contents of the file. In addition, a file can be used by multiple programs simultaneously. So you will not get necessarily exceptional. While using the java.io package that is the classes in the package first understand what you are trying to do with the program of the file which you are dealing with, if you miss something in the program then it can be dangerous for the file, that is you can even loose the file.

  4. #4
    Join Date
    Dec 2009
    Posts
    204

    Re: Program to see file used by another process

    Hello,
    Even I am searching for a similar program, I have a treatment that launches executable via Process.exec () and this treatment aims to repatriate me a csv file from the machine that starts the process and creates the csv file into a new file whose name is the date of launch given parameter. But the whole thing is not quite working for me. If you have any solution for this then please help me with this. Thanks in advance.

  5. #5
    Join Date
    Dec 2009
    Posts
    296

    Re: Program to see file used by another process

    Hello,
    This is my updated code please have a look at it and if you find any problems in the code then correct me with the same
    Here is my code:

    Code:
    do {
    				try {
    					Thread.sleep(10000);
    				} catch (InterruptedException e) {				
    					e.getMessage();
    				}
    				try {
    					 f = new File(fluse);
    flinstr = new flinstr(fluse);
    				} catch (FileNotFoundException e1) {			
    					e1.getMessage();
    comments.add("File"+ + fluse"Was not loaded => f not found problem");
    				}
    			} while (! f.canRead());

  6. #6
    Join Date
    Nov 2009
    Posts
    359

    Re: Program to see file used by another process

    Hello,
    Do not know exactly that this is what you want, but have a look at the following code, may help you
    Code:
    try {
    			Process = runtime.getRuntime().exec(shellCommand);
    p.waitfor();
    		} catch (IOException ioe) {		
    			ext.getIOException(ioe);
    comt.add("The file was not executed APPTMP.csv => execution problem");
    		}catch (InterruptedException e) {
    			comt.add("there is a problem of p execution");
    		}

Similar Threads

  1. Replies: 1
    Last Post: 04-02-2013, 10:21 AM
  2. Learning Batch file to open a program or a file
    By Ikshana in forum Windows Software
    Replies: 3
    Last Post: 04-04-2011, 07:24 PM
  3. How do I tell what process owns a file?
    By JamesB in forum Operating Systems
    Replies: 3
    Last Post: 27-07-2009, 08:45 PM
  4. How to conclude Which Windows Process is Using a File
    By Jaisudha in forum Operating Systems
    Replies: 3
    Last Post: 06-07-2009, 11:59 AM
  5. Replies: 1
    Last Post: 26-03-2009, 06:31 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
  •