I am creating some files and file names are being fetched from database.
There is a file name called
CUA/ICOR Digital Collection.
But, because of forward slash, "CUA" is getting treated as directory.
I have found Forward slash in Java Regex
and I have tried:
String fileName = "CUA/ICOR Digital Collection";
fileName = fileName.replaceAll("/", "\\\\/"); // OP: CUA\/ICOR Digital Collection But No success
fileName = fileName.replaceAll("/", Matcher.quoteReplacement("\\/")); // OP: CUA\/ICOR Digital Collection But No success
fileName = fileName.replaceAll("/", Matcher.quoteReplacement("\\\\/")); // OP: CUA\\/ICOR Digital Collection But No success
File file = new File(exportPath, fileName + ".xls");
I am getting
File Not Found Exception At 'C:\export\CUA\ICOR Digital Collection.xls'
So, Now I doubt is it possible ?
On Windows, a file can't contain /\:*?"<>|
You're better off converting the / character to something like an underscore (_)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With