Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

how to delete a file  RSS feed

 
sachin raj
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How deleate a file "abc.txt" from a directory ?
 
Matt Senecal
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try this:
 
sachin raj
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am giving the code written by me.It is not deleting the file "abc.txt".I am working in windows environment.could you plese tell me what is my mistake ?
public class test
{
public static void main(String args[])
{
File f=new File("C:/project/abc.txt");
f.deleate()
}
}
 
huaqing liu
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The file string should be this C:\\project\\abc.txt assuming this win32.
Good luck.
 
sachin raj
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried "c:\\project\\abc.txt" also.But it is also not working.
Atlest it is not givining any error.
f.delete() is returning false.
 
bob morkos
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try with this:
public static void main(String argv[]){
String[] filenames;
String[] files=null;
File f = new File("Download");
filenames = f.list();
for(int i=0; i< filenames.length; i++) {
File fs= new File(f.getName() + File.separator + filenames[i]);
fs.delete();
}
 
sachin raj
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ya,It is working
Thanq very much bob, morkos
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!