I have a simple program which reads a file. Now there is a blank space in between the line. I get the StringIndexOutOfBoundsException: String index out of range: 0 error there. Please help
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);
}
}