1

I have a Java code which uses the JFileChooser component and it gets the folder path in the format D:\Folder\subfolder.

When I use this path to create a new file it does not accept.

So, is there a way I can convert this path to D:\\release\\subfolder or is there any other way to proceed?

Tom
  • 16,842
  • 17
  • 45
  • 54
Harsha
  • 349
  • 1
  • 8
  • 20

1 Answers1

1

String replacement can be the answer.

public class FilePathChanger {
    public static void main(String[] args) {
        String filePath = "D:\\Folder\\subfolder";
        filePath = filePath.replace("\\", "\\\\");
        System.out.println(filePath);
    }
}

Hope it will help you.

SkyWalker
  • 28,384
  • 14
  • 74
  • 132