Reputation: 41
I'm trying to remove ".txt"
extension from my file name yet I'm getting a NullPointerException
on line 2.
Filename equals "myfilename.txt"
and It's a string, I'd tried printing it
String token[]=fileName.split(".");
File JSONFile = new File(rootFile.getPath()+"\\"+token[0]+ ".json");
Upvotes: 0
Views: 58
Reputation: 3433
.
is a special character so you need to escape it with backslash \\
Try this:
String token[] = fileName.split("\\.");
File JSONFile = new File(rootFile.getPath()+"\\"+token[0]+ ".json");
Upvotes: 2