How do you read files with metacharacters in the file name? For example:
private void readDoc (String path) {
try {
SAXReader reader = new SAXReader();
this.doc = reader.read("_40208#1159SOV.xml");
} catch(Exception e) {
this.print(e.getMessage()); } }
I tried using:
reader.read(Pattern.quote("_40208#1159SOV.xml");
but it doesn't work. Would like a solution that does not require renaming the files. Thank you.
read
treats the system id as if it were a URL. #
denotes an anchor in a URL so the method looks for a file named _40208
which doesnt exist. You can encode the argument
Document doc = reader.read(URLEncoder.encode("_40208#1159SOV.xml", "UTF-8"));
path to file's is getting from UI dialog (JFileChooser) which returns string
In this case the solution is even simpler: SAXReader
provides an overloaded method which uses a File
reference
Document doc = reader.read(filechooser.getSelectedFile());