File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

How to delete the file with space in name?

rama ilango

Joined: Dec 11, 2008
Posts: 24
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

Joined: Oct 29, 2001
Posts: 8707

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

Joined: Oct 27, 2005
Posts: 19541

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

How To Ask Questions How To Answer Questions
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 60050

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

Joined: Oct 14, 2005
Posts: 18121

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:
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?