This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Java in General and the fly likes Creating folers anf files in Unix using java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Java in General
Bookmark "Creating folers anf files in Unix using java" Watch "Creating folers anf files in Unix using java" New topic
Author

Creating folers anf files in Unix using java

sivakumar damodaran
Greenhorn

Joined: Jul 30, 2008
Posts: 2
I'm trying to create folders and files in UNIX. The problem is the folder name and file name has space in it, but UNIX doesn't allow to space in them. Is there a way to do it?


Regards,<br />Sivakumar,<br />PLM System Analyst
Ulf Dittmer
Rancher

Joined: Mar 22, 2005
Posts: 42958
    
  73
Welcome to JavaRanch.
but UNIX doesn't allow to space in them.

I've no problem creating a directory containing a space, either using File.mkdir or on the command line. How are you trying to do that?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 20078
    
  30

Unix allows just about anything in file / folder names, including spaces and even other characters usually used by the shell. I even managed to create files that start with a -; it's a real trick trying to delete those I tell you, since rm thinks it's a flag for it.

The trick is, on the shell you need to either encapsulate the file name in double quotes "", or use \ as an escape character. So listing all files in folder "My Folder" could be done as follows:


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
sivakumar damodaran
Greenhorn

Joined: Jul 30, 2008
Posts: 2
I tried all these but nothing works
Ulf Dittmer
Rancher

Joined: Mar 22, 2005
Posts: 42958
    
  73
What happened when you tried to do this on the command line?

What happened when you tried to do this in Java code?

TellTheDetails
 
Have you checked out Aspose?
 
subject: Creating folers anf files in Unix using java
 
jQuery in Action, 3rd edition