• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Deleting a file. HELP!

 
Ben Wong
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21322
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 21427
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic