Rocking
asked on
File not deleted Apache utils
Hi,
I have written the code for copying the file,once the file is copied,need to delete the same,but the file is not getting deleted..
Kindly let me know the cause why file is not deleted.
Code is as below
I have written the code for copying the file,once the file is copied,need to delete the same,but the file is not getting deleted..
Kindly let me know the cause why file is not deleted.
Code is as below
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
public class FileCopy {
public static void main(String arg[]) {
try {
IOUtils.copy(new FileInputStream("C:\\temp\\abc.txt"),
new FileOutputStream("C:\\temp_del\\abc.txt"));
File f = new File("C:\\temp_del\\abc.txt");
[subtitle]//file delete code not working[/subtitle]
[u] FileUtils.deleteQuietly(f);[/u]
} catch (IOException e) {
e.printStackTrace();
}
}
}
The deleteQuietly method will not throw any exception if there is something wrong, it just returns true (if the file is deleted) or false (if the file is not deleted). I'd suggest you use File.delete() and see if it throws any exception. Then we can investigate the cause of the exception.
Why are you copying a file to a destination and then immediately deleting that destination?
ASKER
the file is downloaded and is to be removed once downloaded
the file is downloaded and is to be removed once downloadedNope - that doesn't make sense as an answer i'm afraid ;) You copy A to B and immediately delete B. Now i could understand if you immediately deleted A, but you don't ...
CEHJ obviously this is a tutorial the asker is doing. In a tutorial it does make sense to copy A to B and immediately delete B.
CEHJ obviously this is a tutorial
Really? Tutorials don't frequently use 3rd party libraries in such a way - but maybe you're right ...
Maybe it's an evaluation then of the apache commons.
ASKER
hi,
i got the solution,by closing the output steam.
i got the solution,by closing the output steam.
ASKER
http://technojeeves.com/index.php/aliasjava1/12-copying-streams
Is it possible to read fairly large file 4gb?
Is it possible to read fairly large file 4gb?
Yes, no problem. Big files are probably better copied with nio though
ASKER
what about copyLarge in apacheutils package? Is is better than nio?
No, worse ;)
ASKER
Can we getBytes of a large file (4gb) through nio?
http://docs.oracle.com/javase/7/docs/api/java/nio/file/Files.html#readAllBytes%28java.nio.file.Path%29
http://docs.oracle.com/javase/7/docs/api/java/nio/file/Files.html#readAllBytes%28java.nio.file.Path%29
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
:)