Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Read Unicode filename

807603Oct 13 2006 — edited Feb 26 2008
Hi,
I am new in Java and facing problem with reading unicode filename. I tried to read a xml file that stored in desktop with chinese character filename using java but it return exception when come to this line of code - xmldoc = builder.build(inputFile);

Below is the code i have wrote:

Document xmldoc = null;
String xmlDirectory = null;
SAXBuilder builder = new SAXBuilder("org.apache.xerces.parsers.SAXParser");
.....
xmlDirectory = "C:\\Documents and Settings\\user\\Desktop\\";
String inputFile = xmlDirectory + fileName;

xmldoc = builder.build(inputFile);
.......


And the exception returns is as below:

java.io.FileNotFoundException: C:\Documents and Settings\user\Desktop\??_1_ref.xml (The filename, directory name, or volume label syntax is incorrect)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:106)
at java.io.FileInputStream.<init>(FileInputStream.java:66)
at sun.net.www.protocol.file.FileURLConnection.connect(FileURLConnection.java:69)
at sun.net.www.protocol.file.FileURLConnection.getInputStream(FileURLConnection.java:156)
at java.net.URL.openStream(URL.java:913)
at org.apache.xerces.impl.XMLEntityManager.startEntity(XMLEntityManager.java:731)
at org.apache.xerces.impl.XMLEntityManager.startDocumentEntity(XMLEntityManager.java:676)
at org.apache.xerces.impl.XMLDocumentScannerImpl.setInputSource(XMLDocumentScannerImpl.java:252)
at org.apache.xerces.parsers.StandardParserConfiguration.parse(StandardParserConfiguration.java:499)
at org.apache.xerces.parsers.StandardParserConfiguration.parse(StandardParserConfiguration.java:581)
at org.apache.xerces.parsers.XMLParser.parse(XMLParser.java:147)
at org.apache.xerces.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1157)
at org.jdom.input.SAXBuilder.build(SAXBuilder.java:453)
at org.jdom.input.SAXBuilder.build(SAXBuilder.java:891)
...........................................


The fileName is "����_1_ref.xml" (it is actually in chinese character). However, if normal fileName, such as "1_ref.xml", the above code is actually working fine.

May i know how to solve this issue?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 25 2008
Added on Oct 13 2006
10 comments
2,084 views