Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

how to use the delete method  RSS feed

 
peter moss
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is the code:
<%@ page import="java.io.*" %>
<%
File dir = new File("/DATA/test/");
String[] files = dir.list();
for (int i = 0; i < files.length; i++) {
out.print("Name: " + files[i] + " <br>");
}
//this is the part i'm having trouble with
dir.delete("test.txt");
%>

I've got this saved in a file called delete.jsp and this is the error I get:
delete() in java.io.File cannot be applied to (java.lang.String)
dir.delete("deleteme.jpg");
^

Please help. This is running on Red hat under apache tomcat
 
Archana Annamaneni
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can do like that .
You have to create the File object with the file name and then do the delete.
That is
File f = new File("/DATA/iocns/some.jpg");
if(f.exists())
{
f.delete();
}
Try that .
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65824
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Despite the code being in a JSP, this is not a JSP question and so I'm moving it to the I/O forum.
bear
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Note that you really should check the return value of the delete method to make sure it worked:

There are various things that can go wrong here, so be careful to check your results as you go.
[ September 08, 2003: Message edited by: Jim Yingst ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!