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

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

Open in new window

RockingAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

girionisCommented:
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.
0
CEHJCommented:
Why are you copying a file to a destination and then immediately deleting that destination?
0
RockingAuthor Commented:
the file is downloaded and is to be removed once downloaded
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

CEHJCommented:
the file is downloaded and is to be removed once downloaded
Nope - 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 ...
0
girionisCommented:
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.
0
CEHJCommented:
CEHJ obviously this is a tutorial

Really? Tutorials don't frequently use 3rd party libraries in such a way - but maybe you're right ...
0
girionisCommented:
Maybe it's an evaluation then of the apache commons.
0
RockingAuthor Commented:
hi,
i got the solution,by closing the output steam.
0
CEHJCommented:
0
RockingAuthor Commented:
http://technojeeves.com/index.php/aliasjava1/12-copying-streams

Is it possible to read fairly large file 4gb?
0
CEHJCommented:
Yes, no problem. Big files are probably better copied with nio though
0
RockingAuthor Commented:
what about copyLarge in apacheutils package? Is is better than nio?
0
CEHJCommented:
No, worse ;)
0
RockingAuthor Commented:
0
CEHJCommented:
http://docs.oracle.com/javase/8/docs/api/java/nio/file/Files.html#copy-java.nio.file.Path-java.io.OutputStream-

is what you should use for copying - why are you interested in the bytes?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CEHJCommented:
:)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.