wood burning stoves 2.0*
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 Murach's Java Servlets and JSP this week in the Servlets 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: 8836


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

Joined: Oct 27, 2005
Posts: 19651

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

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

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
Increasing Disk Partition Size on Linux
Executing a UNIX shell script using JAVA
problem of brackets running file bat
Recovery of file after removing it?
how to read file name which contains space?