문자열의 특정 문자를 받기다를 수 있습니다 내가 문자열을
"/this/is/my" and "file.txt"
나는이 방법을 시도를하지만 실패 (충돌) :
int counter = 0;
filePath = "/this/is/my/file.txt";
String filePath2 = filePath.substring(filePath.lastIndexOf("/") + 1); // return "file.txt"
for (int i = 0; i < filePath2.length(); i++) {
counter++; // count number of char on filePath2
}
String filePath3 = filePath3.substring(filePath.lastIndexOf("") + counter); // Remove "file.txt" from filePath2 depending of character numbers on filePath2 backwards
누구나 더 좋은 방법을 알고 계십니까? 감사!
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 to start activity ComponentInfo{br.fwax.paulo.flasher/br.fwax.paulo.flasher.MFlasher}: java.lang.StringIndexOutOfBoundsException: length=21; index=29
시도해보십시오.'String filePath3 = filePath.replace (filePath2, "");'- 원본 (전체 경로)을 얻으려면 - 파일. –
방법 문자열 filePath3 filePath.substring = (0, filePath.lastIndexOf ("/") + 1); – aadi53