It's not a secret anymore!*
The moose likes Java in General and the fly likes Deleting a file. HELP! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Deleting a file. HELP!" Watch "Deleting a file. HELP!" New topic
Author

Deleting a file. HELP!

Ben Wong
Greenhorn

Joined: Mar 27, 2006
Posts: 19
Hi

i am still trying to get a JAR version of my program fully functioning but im getting problems.

For all referenced files i use the class path from class.getResource(). however, for some reason I cannot delete files from the filesystem. It worked before but not anymore! this is the code im using:


please help!

Ben
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18564
    
    8

The getResource method returns you a URL object, so the code you have posted should not compile. At any rate, assuming your real code looks more likethen -- also assuming the resource is actually in the file system and not inside the jar -- then I think calling its getPath() method should give you the file name. A little experimenting with System.out.println should show you what you are dealing with.
[ April 26, 2006: Message edited by: Paul Clapham ]
Ben Wong
Greenhorn

Joined: Mar 27, 2006
Posts: 19
yeah sorry about that. In my real code i wrote:


The problem I've notice and completely confused by is that when i call a f.exists() it returns false, even though i know it definitely does exist! ive been using loads of System.out.println() lines to try to find out whats going on.

when i change the code and use File f = new File("folder/thefile.xml"); it works fine. but the code then reads the file from OUTSIDE of the JAR, even though the file and folder exist inside the JAR.

im totally confused! please help!
[ April 26, 2006: Message edited by: Ben Wong ]
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18825
    
  40

I don't think the toString() method returns what you want. If memory serves, it should be a string representation of the URL -- and not a file path and name.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
 
subject: Deleting a file. HELP!