1 FileChooser fileChooser = new FileChooser();
2 fileChooser.setTitle("选择你要查看的文件");
3 File file = fileChooser.showOpenDialog(null);
4 String path = file.getPath().toString();
5 String str = path.replaceAll("\\\\","\\\\\\\\");
When I want to go through FileChooser to open a picture, and by Imageview time display, found it file.getPath (); can not be used directly, need to convert the format to use File: D: \\ * PNG. , file.getPath () Gets the path to D:. \ * PNG , which is obviously undesirable. So by String inside replaceAll this method the "\" replaced by "\\" , but can not be found directly. Later Baidu, a "\" need four "\" to function properly replaced.