473,394 Members | 1,709 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

deleting files

Tin
I am having trouble using java.io.File.delete(). 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.getAbsolutePath();
String newName = null;
if(f.isFile()) {
if(oldName.substring(oldName.length() - 4).equals(".enc")) {
newName = oldName.substring(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 RuntimeException("Cannot Delete");
}

} catch(IOException e) {
System.out.println("error " + e );
}
}
....
Jul 17 '05 #1
1 3686
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.ac.nz> wrote in message
news:Xn*****************************@202.20.93.13. ..
I am having trouble using java.io.File.delete(). 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.getAbsolutePath();
String newName = null;
if(f.isFile()) {
if(oldName.substring(oldName.length() - 4).equals(".enc")) {
newName = oldName.substring(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 RuntimeException("Cannot Delete");
}

} catch(IOException e) {
System.out.println("error " + e );
}
}
...

Jul 17 '05 #2

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

Similar topics

0
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...
5
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...
3
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...
0
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...
6
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...
3
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...
2
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...
7
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...
3
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,...
0
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. ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...

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.