2 Replies Latest reply on Mar 24, 2009 7:44 AM by 807588

    How to get the process blocking a file

      Hi all,

      How can we list all processes blocking/using a file ?
      Is it possible ?

      Any type of input welcome.

        • 1. Re: How to get the process blocking a file
          I've personally never done this in Java, but I have used an application called Process Explorer. Google it. It can search for processes that have locked a particular file.
          • 2. Re: How to get the process blocking a file
            I think you can not find out the process using a file. but i can give you an idea by which you can explore all process on your system By which youcan sort out which process is using file by looking at the process.
            1. Create a RunTime <Runtime run = Runtime.getRuntime();>
            2. create a process for command <TaskList>
            3. retrive it in bufferedReader
            4. Now you have all process running on you system in your hand.
            5. find out which is using file by the name of the process.

            try {   
            Runtime run = Runtime.getRuntime();
            String locsasexe = "TASKLIST" ;
            Process pp = run.exec(locsasexe);
            BufferedReader in = new BufferedReader(new InputStreamReader(pp.getInputStream()));
            String line;
            while ((line = in.readLine()) != null) {
            int exitVal = pp.waitFor();
            } catch (Exception ex) {