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
.NET Public-Key (Asymmetric) Cryptography DemoJuly 20, 2025
Raspberry Pi 3B+ Photo FrameJune 17, 2025
EBTCalc (Android) Version 1.53 is now availableMay 19, 2024
Vault 3 Security EnhancementsOctober 24, 2023
Vault 3 is now available for Apple OSX M2 Mac Computers!September 18, 2023
Vault (for Desktop) Version 0.77 ReleasedMarch 26, 2023
EBTCalc (Android) Version 1.44 is now availableOctober 12, 2021