File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes How to delete the file with space in name? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to delete the file with space in name?" Watch "How to delete the file with space in name?" New topic
Author

How to delete the file with space in name?

rama ilango
Greenhorn

Joined: Dec 11, 2008
Posts: 24
Hi
I want to delete the file "test ex.txt" file.
i run the following command in command prompt.i can delete the file successfully.
/bin/rm -f /mnt/"test ex.txt"

I want to run the command from java.So i am using the following code
String cmd = "/bin/rm -f /mnt/\"test ex.txt\"";
Runtime rt = Runtime.getRuntime();
process = rt.exec(cmd);
The file was not deleted.
How to delete the file with space in name?
Help me
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8707
    
    6

java.io.File.delete()


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19541
    
  16

As a reference, put the quotes around the entire path, not just the file name.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60050
    
  65

Please take the time to choose the correct forum for your posts. This forum is for questions on advanced Java -- something this is definitely not.

For more information, please read this.

This post has been moved to a more appropriate forum.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18121
    
    8

If the question is actually about Java, then here's how to delete a file:

This works no matter how many spaces there are in the name of the file.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to delete the file with space in name?
 
Similar Threads
problem of brackets running file bat
Increasing Disk Partition Size on Linux
Recovery of file after removing it?
Executing a UNIX shell script using JAVA
how to read file name which contains space?