比如两个文件存放在c:\呵呵\1.xml 和c:\2.xml
File f = new File("c:/2.xml");
SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setNamespaceAware(true);
SAXParser parser = factory.newSAXParser();
parser.parse(f.getPath(), this);
就没有问题
但是
File f = new File("c:/呵呵/1.xml");
SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setNamespaceAware(true);
SAXParser parser = factory.newSAXParser();
parser.parse(f.getPath(), this);
就不能读取xml文档要换成
File f = new File("c:/呵呵/1.xml");
SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setNamespaceAware(true);
SAXParser parser = factory.newSAXParser();
parser.parse(f, this);
就可以了
请问为什么呢?
File f = new File("c:/2.xml");
SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setNamespaceAware(true);
SAXParser parser = factory.newSAXParser();
parser.parse(f.getPath(), this);
就没有问题
但是
File f = new File("c:/呵呵/1.xml");
SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setNamespaceAware(true);
SAXParser parser = factory.newSAXParser();
parser.parse(f.getPath(), this);
就不能读取xml文档要换成
File f = new File("c:/呵呵/1.xml");
SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setNamespaceAware(true);
SAXParser parser = factory.newSAXParser();
parser.parse(f, this);
就可以了
请问为什么呢?
File f = new File(java.net.URLDecoder.decode("c:/呵呵/1.xml","UTF-8")); }
catch(Exception e)
{
e.printStackTrace();
} SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setNamespaceAware(true);
SAXParser parser = factory.newSAXParser();
parser.parse(f.getPath(), this); 这样我也试过了,不行的。
* Parse the content described by the giving Uniform Resource
* Identifier (URI) as XML using the specified
* {@link org.xml.sax.HandlerBase}.
* <i> Use of the DefaultHandler version of this method is recommended as
* the <code>HandlerBase</code> class has been deprecated in SAX 2.0</i>
*
* @param uri The location of the content to be parsed.
* @param hb The SAX HandlerBase to use.
*
* @throws IllegalArgumentException If the uri is null.
* @throws IOException If any IO errors occur.
* @throws SAXException If any SAX errors occur during processing.
*
* @see org.xml.sax.DocumentHandler
*/
public void parse(String uri, HandlerBase hb)
throws SAXException, IOException {
if (uri == null) {
throw new IllegalArgumentException("uri cannot be null");
} InputSource input = new InputSource(uri);
this.parse(input, hb);
}
/**
* Parse the content described by the giving Uniform Resource
* Identifier (URI) as XML using the specified
* {@link org.xml.sax.helpers.DefaultHandler}.
*
* @param uri The location of the content to be parsed.
* @param dh The SAX DefaultHandler to use.
*
* @throws IllegalArgumentException If the uri is null.
* @throws IOException If any IO errors occur.
* @throws SAXException If any SAX errors occur during processing.
*
* @see org.xml.sax.DocumentHandler
*/
public void parse(String uri, DefaultHandler dh)
throws SAXException, IOException {
if (uri == null) {
throw new IllegalArgumentException("uri cannot be null");
} InputSource input = new InputSource(uri);
this.parse(input, dh);
}
/**
* Parse the content of the file specified as XML using the
* specified {@link org.xml.sax.HandlerBase}.
* <i> Use of the DefaultHandler version of this method is recommended as
* the HandlerBase class has been deprecated in SAX 2.0</i>
*
* @param f The file containing the XML to parse
* @param hb The SAX HandlerBase to use.
*
* @throws IllegalArgumentException If the File object is null.
* @throws IOException If any IO errors occur.
* @throws SAXException If any SAX errors occur during processing.
*
* @see org.xml.sax.DocumentHandler
*/
public void parse(File f, HandlerBase hb)
throws SAXException, IOException {
if (f == null) {
throw new IllegalArgumentException("File cannot be null");
} String uri = "file:" + f.getAbsolutePath();
if (File.separatorChar == '\\') {
uri = uri.replace('\\', '/');
}
InputSource input = new InputSource(uri);
this.parse(input, hb);
}
/**
* Parse the content of the file specified as XML using the
* specified {@link org.xml.sax.helpers.DefaultHandler}.
*
* @param f The file containing the XML to parse
* @param dh The SAX DefaultHandler to use.
*
* @throws IllegalArgumentException If the File object is null.
* @throws IOException If any IO errors occur.
* @throws SAXException If any SAX errors occur during processing.
*
* @see org.xml.sax.DocumentHandler
*/
public void parse(File f, DefaultHandler dh)
throws SAXException, IOException {
if (f == null) {
throw new IllegalArgumentException("File cannot be null");
} String uri = "file:" + f.getAbsolutePath();
if (File.separatorChar == '\\') {
uri = uri.replace('\\', '/');
}
InputSource input = new InputSource(uri);
this.parse(input, dh);
}