Hi I want to replace a backslash character \
by double backslash character \\
from a string in Java but the replace() method does not seem to work. It gives an arguments mismatch error. I think it does not work with special characters. Any get around to this?
Here is my code snippet:
String fileSeparator = System.getProperty("file.separator");
JFileChooser chooser = new JFileChooser();
chooser.setCurrentDirectory(new java.io.File("."));
chooser.setDialogTitle("Locate Java Documentation Folder");
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
chooser.setAcceptAllFileFilterUsed(false);
if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
JTextField jtfFileLocation=new JTextField();
jtfFileLocation.setText(chooser.getSelectedFile().getPath()+fileSeparator);
String filePath=jtfFileLocation.getText();
filePath.replaceAll("\\", "\\\\");
System.out.println(filePath);
} else {
}