• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to escape whitespace in file path

 
venkatesh seshagiri
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi EveryBody
I am reading a file which consist of space in its name. The location of the file is
C:/Documents and Settings/venkatesh/XMLtest/ListPageDisplayPropertiesMapping.xml

The exception that i am getting is attached at the end of this message for reference. Simplest thing that can be done is i can change the directory name so that there are no spaces. However this file path is take dynamically. That is this application can run on both unix and windows. Hence the application when compiled, the executables are placed at user's home directory.

Is there a way by which i can encode the file path such that whitespaces are taken care.

Thanks for the help

S venkatesh

[2004-11-05 13:06:31 ] <main> com.webobjects.foundation.NSForwardException for java.net.MalformedURLException: unknown protocol: c
at java.net.URL.<init>(URL.java:586)
at java.net.URL.<init>(URL.java:476)
at java.net.URL.<init>(URL.java:425)
at org.apache.xerces.impl.XMLEntityManager.startEntity(XMLEntityManager.java:807)
at org.apache.xerces.impl.XMLEntityManager.startDocumentEntity(XMLEntityManager.java:753)
at org.apache.xerces.impl.XMLDocumentScannerImpl.setInputSource(XMLDocumentScannerImpl.java:260)
at org.apache.xerces.parsers.DTDConfiguration.parse(DTDConfiguration.java:499)
at org.apache.xerces.parsers.DTDConfiguration.parse(DTDConfiguration.java:581)
at org.apache.xerces.parsers.XMLParser.parse(XMLParser.java:152)
at org.apache.xerces.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1114)
at com.webobjects.appserver.xml._private._MappingModel.mappingModelWithXMLFile(_MappingModel.java:405)
at com.webobjects.appserver.xml._private._WOXMLMappingDecoder.<init>(_WOXMLMappingDecoder.java:121)
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure this is your problem (yet). It's more likely that, as the eror says, you're not using the correct protocol for the URL.

When accessing files on the file path, I believe the URL format is "file://c:/etc etc" ie we're using the 'file' protocol. THis may then lead your your space problem.
 
venkatesh seshagiri
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the inputs.

Using the file as the protocal it works. That is changed the file path
from

C:/Documents and Settings/venkatesh/XMLtest/ListPageDisplayPropertiesMapping.xml to


file:/C:/Documents and Settings/venkatesh/XMLtest/ListPageDisplayPropertiesMapping.xml.

I would like to understand the significance of adding file:/ before the file path when there is space in the file name. When there is no space in the file name without appending the 'file:/' it works.

Thanks
Venkatesh
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The URL classes (why aren't you just opening the file directly with "new File(name)"?) might attempt to detect a filename when there's no protocol specified (the "file://"), and if so perhaps spaces make it think it's not a file.

If you really need to know, open up the code in java.net.URL and friends and find out.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic