【发布时间】:2014-03-07 16:26:06
【问题描述】:
我有一个读取文件的简单程序。现在行之间有一个空格。我得到 StringIndexOutOfBoundsException: String index out of range: 0 错误。请帮忙
class main{
public static void main(String args[]) {
String str;
try {
BufferedReader br = new BufferedReader ( new FileReader("train.txt"));
while((str=br.readLine())!=null){
System.out.println(str);
int a=str.charAt(0);
if(str.trim().length()==0){
System.out.println("stupid");
}
else if(a==32){
System.out.println("ddddd");
}
else if(str.charAt(0)=='A' ||str.charAt(0)=='a'){
System.out.println("hahha");
}
else if(str.charAt(0)=='C' ||str.charAt(0)=='c'){
System.out.println("lol");
}
else if(str.charAt(0)=='D' ||str.charAt(0)=='d'){
System.out.println("rofl");
}
else{
System.out.println("blank");
}
}
}
catch (FileNotFoundException e){
System.out.println(e);
}
catch (IOException e){
System.out.println(e);
}
}
【问题讨论】:
-
Arrival Mar 21, 2014 10:30 38472 Super Express Cancel 40003 这是我文件中包含的数据。我的代码无法越过到达线和取消线之间的空白区域
-
使用堆栈跟踪发布您的异常。
标签: java bufferedreader