开发者

why is toString() returning a "/" to my String path? [closed]

开发者 https://www.devze.com 2023-03-24 04:32 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form. For help clari
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

I have a toString() method that is returning a "/" at the beginning of the String, which is a filepath. this is seriously screwing up my program because it's not able to read the resource with that "/" in front:

public String toString() {
    return this.value;
  }

Any help would be greatly appreciated,

Edit:

Here's the c开发者_如何学运维onstant:

DELEGATE_JNDI_NAME("java:/comp/env/jndi/delegates"),


I'm guessing you're trying to pass the "java:/comp/emv/jndi/delegates" as an argument to your toString() method. I don't see any leading /'s, but if you do get one, use this method to remove it...

String removeSlash(String file) {
     char[] letters = file.toCharArray();
     if (file.charAt(0) == '/'){ //first character is '/'
         return file.substring(1);
     } else {
         return file;
     }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消