473,548 Members | 2,716 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

deleting files

Tin
I am having trouble using java.io.File.de lete(). The following code always
throws an exeption. The file cannot be deleted. I am running windows 98 and
the program is an application, not an applet Why? I appreciate any help.
Thanks in advance.

Tin
tp**@waikato.ac .nz
public void protect(File f) {
String oldName = f.getAbsolutePa th();
String newName = null;
if(f.isFile()) {
if(oldName.subs tring(oldName.l ength() - 4).equals(".enc ")) {
newName = oldName.substri ng(0, oldName.length( ) - 4);
}
else
newName = oldName + ".enc";
try {
// Create the encrypted files
(new Encryptor(mKey, f, new File(newName))) .encrypt();
//Delete the old file
if(!f.delete()) { // This is the line that causes problems
throw new RuntimeExceptio n("Cannot Delete");
}

} catch(IOExcepti on e) {
System.out.prin tln("error " + e );
}
}
....
Jul 17 '05 #1
1 3697
Did you check the permissions of the file? Maybe it is read only, or
maybe it is open by another application or a system process when
you try to delete it.

"Tin" <tp**@waikato.a c.nz> wrote in message
news:Xn******** *************** ******@202.20.9 3.13...
I am having trouble using java.io.File.de lete(). The following code always
throws an exeption. The file cannot be deleted. I am running windows 98 and the program is an application, not an applet Why? I appreciate any help.
Thanks in advance.

Tin
tp**@waikato.ac .nz
public void protect(File f) {
String oldName = f.getAbsolutePa th();
String newName = null;
if(f.isFile()) {
if(oldName.subs tring(oldName.l ength() - 4).equals(".enc ")) {
newName = oldName.substri ng(0, oldName.length( ) - 4);
}
else
newName = oldName + ".enc";
try {
// Create the encrypted files
(new Encryptor(mKey, f, new File(newName))) .encrypt();
//Delete the old file
if(!f.delete()) { // This is the line that causes problems
throw new RuntimeExceptio n("Cannot Delete");
}

} catch(IOExcepti on e) {
System.out.prin tln("error " + e );
}
}
...

Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1451
by: Michał Januszczyk | last post by:
Hello. I've got the following problem: I created a windows installer project that installs my application. The application works with some files. I want to include some example files with the installation package. These files by no means are critical for the application itself. They are included only to help application user to get...
5
16763
by: Rosa | last post by:
Hi, I'm trying to clear the TIF on Windows XP programmatically with the below code. This code works fine on any folder but the TIF. For some reason the atEnd() statements always defaults to true and no files are deleted in the folder. The peculiarity of this issue is that the files/subfolders cannot be seen through the windows explorer...
3
1988
by: Mike Turco | last post by:
I'm working on an application that imports and exports tons of CSV data, like 64,000 records per file, and six or seven files in a set. First off, by the tine I import a few hundred thousand records the database is _huge_. Like 500 meg, although the csv files are only 25 meg in total. When I compact the database its still 100meg. How do I...
0
1395
by: Hrvoje Vrbanc | last post by:
Hello, this is a problem I came upon while building a site based on MCMS 2002 but it's not strictly MCMS-oriented: I have a page that displays a certain content in presentation mode but when an editor clicks "Switch To Edit Site" in MCMS console on the page, the page displays a different content, an interface that editor use for upload and...
6
4547
by: Martin Bischoff | last post by:
Hi, I'm creating temporary directories in my web app (e.g. ~/data/temp/temp123) to allow users to upload files. When I later delete these directories (from the code behind), the application restarts and all active sessions are terminated. This error is also described in detail here:...
3
1560
by: Martin Ho | last post by:
Can someone help me with this please? I wasn't very clear in my old post. I have a program to copy files from one location to another, now I want to copy only those files which were created on certain date. How do I compare the file (date created) to system date? Something like this doesn't work: if System.IO.File.GetCreationTime(path to...
2
2531
by: Josh Kandiko | last post by:
Hi, I've been having some frustrations with deleting files from the Isolated Storage directories. Basically, I want my application to remove all instances of configuration information for my application when the application is uninstalled. So, I created an uninstaller class that overrides the uninstall method, as follows: private void...
7
1828
by: eSolTec, Inc. 501(c)(3) | last post by:
Thank you in advance for any and all assistance. I have an application that pulls files, folders and registry keys of installed programs. I'm wanting to with a context menu selection of "Delete Selected", delete "ALL" of the checked selected files, folders, registry keys. Can someone show me some code to do this please?
3
2866
by: Kimera.Kimera | last post by:
I'm trying to write a program in VB.net 2003 that basically deletes all files, folders, sub-folders and sub-sub folders (etc). The program is simply for deleting the Windows/Temp folder contents, removing all the files/folders inside it. The problem i am having is that i can only delete files in the Windows/Temp folder, and i can't delete...
0
1188
by: DanInTacoma | last post by:
We have a fairly straightforward maint plan on one of our servers (MSSQL 2K)...it backs up several DB's to a folder on another server (the one with the tape drive) so they can be archived to tape. The .BAK files have a "Keep for" time of 5 days, and that seems to be working Fine Business...the .TRN files have a "Keep for" time of 7 days, but they...
0
7518
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7711
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7805
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6039
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5367
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5085
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3497
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1932
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1054
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.