Eric Bergman-Terrell's Blog

Java Programming Tip: Parsing an XML File with Embedded Spaces with SAX
November 23, 2008

If you pass a file path string as the first parameter to SAXParser.parse, the file path cannot contain any embedded spaces. Instead, create a FileInputStream object associated with the file path, and pass that object to SAXParser.parse:

// If the first argument to parse is a filename with embedded spaces, an exception will be thrown. The solution is to
// use a FileInputStream instead of a file path.
SAXParser saxParser = saxParserFactory.newSAXParser();
ImportDefaultHandler importDefaultHandler = new ImportDefaultHandler();

FileInputStream inputStream = new FileInputStream(filePath);
saxParser.parse(inputStream, importDefaultHandler);
Keywords: Java, XML, SAX, parsing, SAXParser, FileInputStream

Reader Comments

Comment on this Blog Post

Recent Posts

TitleDate
Java Programming Tip: SWT Photo Frame ProgramOctober 31, 2016
Vault 3 (Desktop) Version 1.63 ReleasedSeptember 9, 2016
"Compliance with Court Orders Act of 2016"April 9, 2016
Disable "Visual Voicemail" on Android / T-MobileJanuary 17, 2016
IPv6 HumorDecember 10, 2015
Java Programming Tip: Specify the JVM time zoneDecember 7, 2015
Node.js / Express Programming Tip: Detect and Fix Memory LeaksOctober 27, 2015