Forums Register Login

Deleting a file. HELP!

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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 ]
+Pie Number of slices to send: Send
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 ]
+Pie Number of slices to send: Send
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
Trust God, but always tether your camel... to this tiny ad.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1016 times.
Similar Threads
XML parsing question (nanoxml)
servlet help!
Creating XML file ? (I can read/cannot write)
Need to Read XMl File From Java Code
xml.transform and stylesheets?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 01:30:46.