Read file with whitespace in name using Java?
java, path
Solution
Use File, it works with whitespaces:
String path = "file:///opt/storage/user-data/attachments/1_00100\\ 0042.jpg";
File f = new File(path);
If you want to replace spaces with %20 then use regex:
path.replaceAll("\\u0020", "%20");
Problem
The original name of file is `1_00100 0042.jpg`. I have a problem: ``` java.net.URISyntaxException: Illegal character in path at index 49: file:///opt/storage/user-data/attachments/1_00100\ 0042.jpg ``` Can you give me some solutions how to get this file using this bad path? I know that C# have Path class. Is there something similar in Java? I tried to do next but not successfully: ``` private String replaceWhitespace(String str) { if (str.contains(" ")) { str = str.replace(" ", "%20"); } return str; } ```