Solved Having problems with .split(File.separetor);

Discussion in 'Plugin Development' started by MGlolenstine, May 26, 2017.

Thread Status:
Not open for further replies.
  1. Ok, so I'm having problems with this line of code:
    Code:
    String[] split = strData.toString().split(File.pathSeparator);
    I get an interesting error:
    Code:
    Caused by: java.util.regex.PatternSyntaxException: Unexpected internal error near index 1
    \
    ^
            at java.util.regex.Pattern.error(Unknown Source) ~[?:1.8.0_131]
            at java.util.regex.Pattern.compile(Unknown Source) ~[?:1.8.0_131]
            at java.util.regex.Pattern.<init>(Unknown Source) ~[?:1.8.0_131]
            at java.util.regex.Pattern.compile(Unknown Source) ~[?:1.8.0_131]
            at java.lang.String.split(Unknown Source) ~[?:1.8.0_131]
            at java.lang.String.split(Unknown Source) ~[?:1.8.0_131]
            at xyz.mglolenstine.MGEggWars.CommandEW.copy(CommandEW.java:82) ~[?:?]
            at xyz.mglolenstine.MGEggWars.CommandEW.onCommand(CommandEW.java:28) ~[?:?]
    And yeah. I'd assume, that the problem comes from
    Code:
    File.separetor
    because it equals to '\' which is an escape character.
    How would I solve that error?
     
  2. Offline

    timtower Administrator Administrator Moderator

  3. Does it matter? Well, I'd like to get server's root directory, but that isn't the point,
     
  4. Offline

    timtower Administrator Administrator Moderator

    It kinda is though.
    Get the File instance, then you can call getParentFolder() or something similar.
     
  5. Ah... Thanks!

    What is the difference between .getParent() and .getParentFile()?
     
  6. Offline

    Zombie_Striker

    @MGlolenstine
    getParent returns a the path to the file, which is a String. getParentFile returns the File instance.
     
  7. Thanks. Ok, so now I used .getAbsolutePath(), how would I go to the parent directory?
     
  8. Offline

    timtower Administrator Administrator Moderator

    @MGlolenstine None of the used methods are reliable though, you can change the plugin directory to a folder that is in the system root while the server is somewhere at the end.
    Why do you need the server root?
    I don't see any use for that besides making a centralized library folder.
     
  9. Well... I'm copying some files to the root of the server I host because it can only be read from there.

    EDIT: I found a solution. I'm just gonna be using this from now on:
    Code:
    File root = new File(plugin.getServer().getWorldContainer().getAbsolutePath());
    Thanks for all the help, you guys are doing a great job!
     
Thread Status:
Not open for further replies.

Share This Page