I think you want to delete the last five characters ('.', 'N', 'u', 'l', 'l'):
path = path.substring(0, path.length() - 5);
Note how you need to use the return value. Strings are immutable, so substring (and other methods) do not change the existing string - they return a link to a new string with the corresponding data.
Or be a little safer:
if (path.endsWith(".null")) { path = path.substring(0, path.length() - 5); }
However, I will try to solve the problem above. I assume that you only have ".null", because some other code does something like this:
path = name + "." + extension;
where extension is null. I would prefer that you never get bad data instead.
(As noted in the interrogative comment, you really need to look at the String API . This is one of the most commonly used classes in Java, so there is no excuse for not being familiar with it.)
Jon Skeet Feb 03 2018-12-12T00: 00Z
source share