I have a String that stores a path. When I print the path, it is like: D:\UnderTest\wavtester.wav. In this string I wanted to know the index of the last occurrence of \ character (the goal is to get the name of the file represented in the String), so I tried to use the method:
int x = nameOfAudioFile.lastIndexOf('\');
But I get an error corresponding to this statement saying : unclosed character literal
- What does this error mean?
- How can I solve this error?
The
\character has special functions in character and string constant, so you need to escape it in order to write it itself as a character literal:string.lastIndexOf('\\').Acatually, in order to be portable you probably want to use
File.separatorCharinstead of an explicit character constant. That way you’ll get/on unix instead of\.