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.
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.
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.
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.
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());
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");
}