richard_fairall
asked on
Java 1.6.0. dom4j SAXReader fails reading file with pathname containing spaces
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
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
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Sure CEHJ
It's actually the filepath:
C:\\Documents and Settings\\Owner\\.smartCon trol\\pref erences.xm l
It's actually the filepath:
C:\\Documents and Settings\\Owner\\.smartCon
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
document = reader.read(file.toURL());
That would work but so does
document = reader.read(file);
So what's changed in Java 1.6?
That would work but so does
document = reader.read(file);
So what's changed in Java 1.6?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
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.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
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
:-)
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.
:-;
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.
:-;
ASKER
try {
SAXReader reader = new SAXReader();
File file = new File(filename);
document = reader.read(file); }
catch (Exception e) {
e.printStackTrace();
// do nothing
}