Java regex to replace file path based on OS

前端 未结 3 1100
没有蜡笔的小新
没有蜡笔的小新 2021-01-14 13:00

I\'m not very sure there is any regex to replace thoese things:

This is a string value read from a xml file saved through Linux machine



        
相关标签:
3条回答
  • 2021-01-14 13:41

    This should take care of fixing slashes:

    String str = xml.replaceAll("\\\\|/", System.getProperty("file.separator"));
    
    0 讨论(0)
  • 2021-01-14 13:46

    Use the "file.separator" system property and base your regexp on that.

    http://docs.oracle.com/javase/tutorial/essential/environment/sysprop.html

    Also see this: File.separator vs FileSystem.getSeparator() vs System.getProperty("file.separator")?

    0 讨论(0)
  • 2021-01-14 14:00

    str = str.replaceAll("\\\\|/", "\\"+System.getProperty("file.separator"))

    0 讨论(0)
提交回复
热议问题