我有一個類似problem.This是我的源的一個片段:字符串索引超出範圍:-1
FileWriter fstream = new FileWriter("results_for_excel.txt");
BufferedWriter writer = new BufferedWriter(fstream);
String sourceDirectory = "CVs";
File f = new File(sourceDirectory);
String[] filenames = f.list();
Arrays.sort(filenames);
String[] res = new String[filenames.length];
for (int i = 0; i < filenames.length; i++) {
System.out.println((i + 1) + " " + filenames[i]);
}
for (int i = 0; i < filenames.length; i++) {
int beg = filenames[i].indexOf("-");
int end = filenames[i].indexOf(".");
res[i] = filenames[i].substring(beg,end);
System.out.println((i+1)+res[i]);
writer.write(res[i] + "\n");
}
writer.flush();
writer.close();
我得到RE的例外[I] =文件名[I] .substring(BEG ,結束); 我無法弄清楚這是怎麼回事on.Thanks提前:) PS我看了所有的重複,但什麼都沒有發生:(
更改'Eithor'到'Either'。 – 2011-03-27 11:22:04