?
Solved

File not deleted Apache utils

Posted on 2014-07-22
16
Medium Priority
?
185 Views
Last Modified: 2014-07-24
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

0
Comment
Question by:Rocking
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 5
  • 3
16 Comments
 
LVL 35

Expert Comment

by:girionis
ID: 40213697
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 40213864
Why are you copying a file to a destination and then immediately deleting that destination?
0
 

Author Comment

by:Rocking
ID: 40214732
the file is downloaded and is to be removed once downloaded
0
WordPress Tutorial 1: Installation & Setup

WordPress is a very popular option for running your web site and can be used to get your content online quickly for the world to see. This guide will walk you through installing the WordPress server software and the initial setup process.

 
LVL 86

Expert Comment

by:CEHJ
ID: 40215279
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
 
LVL 35

Expert Comment

by:girionis
ID: 40216234
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 40216268
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
 
LVL 35

Expert Comment

by:girionis
ID: 40216357
Maybe it's an evaluation then of the apache commons.
0
 

Author Comment

by:Rocking
ID: 40216669
hi,
i got the solution,by closing the output steam.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 40216756
0
 

Author Comment

by:Rocking
ID: 40216881
http://technojeeves.com/index.php/aliasjava1/12-copying-streams

Is it possible to read fairly large file 4gb?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 40216901
Yes, no problem. Big files are probably better copied with nio though
0
 

Author Comment

by:Rocking
ID: 40216912
what about copyLarge in apacheutils package? Is is better than nio?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 40216925
No, worse ;)
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 2000 total points
ID: 40216998
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 40217314
:)
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
This video teaches viewers how to create their own website using cPanel and Wordpress. Tutorial walks users through how to set up their own domain name from tools like Domain Registrar, Hosting Account, and Wordpress. More specifically, the order in…
Learn how to set-up PayPal payment integration in your Wufoo form. Allow your users to remit payment through PayPal upon completion of your online form. This is helpful for collecting membership payments, customer payments, donations, and more.
Suggested Courses
Course of the Month10 days, 4 hours left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question