Solved

Java 1.6.0.  dom4j SAXReader fails reading file with pathname containing spaces

Posted on 2007-03-22
11
333 Views
Last Modified: 2008-02-01
My program uses dom4j 1.6.1 on Windows (Eclipse)
The following code has always worked up to and including Java 1.5.11

      try {
        SAXReader reader = new SAXReader();
        document = reader.read(filename);      }
      catch (Exception e) {
        e.printStackTrace();
      }

Using Java 1.6.0  the code fails at line
        document = reader.read(filename);      }

It generates a DocumentException (Malformed URL)
The problem lies in the pathname having spaces in the folders (C:/Documents and Settings/blah).
Why should this have changed in Java 6? and is there a solution?
Thanks
0
Comment
Question by:richard_fairall
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
11 Comments
 

Author Comment

by:richard_fairall
ID: 18771129
the following solution works... but I'd still like to know why the other fails now
      try {
        SAXReader reader = new SAXReader();
        File file = new File(filename);
        document = reader.read(file);      }
      catch (Exception e) {
        e.printStackTrace();
        // do nothing
      }
0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 450 total points
ID: 18771498
>>It generates a DocumentException (Malformed URL)

Can you post that exact URL?
0
 

Author Comment

by:richard_fairall
ID: 18771798
Sure CEHJ

It's actually the filepath:

C:\\Documents and Settings\\Owner\\.smartControl\\preferences.xml
0
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
LVL 86

Accepted Solution

by:
CEHJ earned 450 total points
ID: 18771922
Yes, that's not good. Try

document = reader.read(file.toURL());      
0
 

Author Comment

by:richard_fairall
ID: 18772021
document = reader.read(file.toURL());      

That would work but so does

document = reader.read(file);
So what's changed in Java 1.6?
0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 450 total points
ID: 18772055
I'm not sure the change is in 1.6
0
 

Author Comment

by:richard_fairall
ID: 18772214
Using eclipse with JDK 1.5.11 using the pathName String works fine.
Using eclipse with JDK 1.6.0 it fails - we can switch back and to between
jdk versions to see the problem.
What is worrying is that this has not been reported before.
Jdom seems ok
No big deal though - there are workarounds.
0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 450 total points
ID: 18772482
Can you print the output in both cases then (what you did before, but for both)
0
 
LVL 30

Assisted Solution

by:Mayank S
Mayank S earned 50 total points
ID: 18772598
>> C:\\Documents and Settings\\Owner\\.smartControl\\preferences.xml

Try:

C:/Documents and Settings/Owner/.smartControl/preferences.xml

- should work in both
0
 

Author Comment

by:richard_fairall
ID: 18773520
The problem here is in switching between Java 1.6 and Java 1.5.11
I have tried forward slashes, backward slashes and a mixture of both - makes no difference.
The problem arises when we switch (in Eclipse) to jre 1.6 from jre 1.5.11 - That's it,
nothing else changed. I can toggle between the two platforms as can my colleagues
in another country - same result - Java 1.6 doesn't allow dom4j SAXParser to work with spaces in folder names. I have seen other people complain about this but they received advice like:
"Take out the spaces"  derr!!
or
"Add quotes around the pathname string"  derr!!
Let's now waste anymore time on this because there is a workaround as I posted at the beginning.
Thanks for your efforts


0
 
LVL 86

Expert Comment

by:CEHJ
ID: 18773856
:-)

Please report if you find anything else as i'm skeptical about

>>The problem arises when we switch (in Eclipse) to jre 1.6 from jre 1.5.11 - That's it,
nothing else changed.

:-;
0

Featured Post

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question