I have a bash script in Linux (CentOS) that redirects output to a file. It takes a few minutes to run:
./myBashScript.sh >> file.csv
I have a java application that tries to read the file (only read) for further processing:
File file = new File("file.csv");
Scanner input = new Scanner(file);
while (input.hasNextLine()) {
String line = input.nextLine();
// do something...
}
These processes are on Crontab
. It works all fine, but apparently whenever the bash script is redirecting the output to the file, the Java app can not read it. The logs shows "File not found"
exception!
Is the file locked?! How can I fix the problem?