java - Get specific characters in a string -
i have string can vary :
string filepath = "/this/is/my/file.txt";
i need string other strings information :
"/this/is/my" , "file.txt"
i tried method failed(crash) :
int counter = 0; filepath = "/this/is/my/file.txt"; string filepath2 = filepath.substring(filepath.lastindexof("/") + 1); // return "file.txt" (int = 0; < filepath2.length(); i++) { counter++; // count number of char on filepath2 } string filepath3 = filepath3.substring(filepath.lastindexof("") + counter); // remove "file.txt" filepath2 depending of character numbers on filepath2 backwards
anyone know better method? thanks!
12-05 15:53:00.940 11102-11102/br.fwax.paulo.flasher e/androidruntime﹕ fatal exception: main process: br.fwax.paulo.flasher, pid: 11102 java.lang.runtimeexception: unable start activity componentinfo{br.fwax.paulo.flasher/br.fwax.paulo.flasher.mflasher}: java.lang.stringindexoutofboundsexception: length=21; index=29
how java's file
class?
file f = new file(filepath); string directory = f.getparent(); string filename = f.getname();
Comments
Post a Comment