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
Node.js + Express: How to Block Requests by User-Agent HeadersJanuary 7, 2026
Vault 3 is Now Available for Windows on ARM Machines!December 13, 2025
Vault 3: How to Include Outline Text in Exported PhotosOctober 26, 2025
.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