I am writting a code for copying a file from one location to another.Code for copying this file is perfect,only thing is while copying a file from one location to another.I am getting this exception
java.io.FileNotFoundException: /Users/Shared/Jenkins/see/rundata/8889/63.PNG (No such file or directory)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:146)
Actually this file generates at runtime and once the code execution is done then this file will not be there.So,I checked it manually while debugging the application and I found that this .png file was there.
public static void copyFile(File sourceFile, File destFile) {
// http://stackoverflow.com/questions/106770/standard-concise-way-to-copy-a-file-in-java
try {
if (!destFile.exists()) {
destFile.createNewFile();
}
FileChannel source = null;
FileChannel destination = null;
try {
source = new FileInputStream(sourceFile).getChannel();
destination = new FileOutputStream(destFile).getChannel();
destination.transferFrom(source, 0, source.size());
} finally {
if (source != null) {
source.close();
}
if (destination != null) {
destination.close();
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
More Info for this Question:-
Actually my application takes screenshot for the each and every screen on my mobile application and puts it in the system and from there i am copying these images in the project by using this method.So,while debugging this method I found that it is able to copy this image file but when I switching off the debug mode image file is not getting copied and I am started getting this no such directory found exception.
So,I thought that it could be something related with sleep time i tried to enter that thing as well by (Thread.sleep(30000)),but no help from this approach.