I had a problem reading a text file in java and assigning it to an array. The program works, but I get null. I tried to change the code to the simplest one, as you see below. Because this one should really scroll the text file. But I do it so that I can easily see where the problem is. But the problem is that I donβt know why it outputs null anyway.
The file is, of course, located in the directory I specified, since the built-in method exists true when I check it with this:
if(ofile.exists()==true){
System.out.println("exist");
}else{
System.out.println("not exist");
}
please, I need help defining the error behind this, why it returns null.
public static void main(String args[]){
String[] eq=new String[50];
String[]ea=new String[50];
String[]eb=new String[50];
String[] ec=new String[50];
String[]ed=new String[50];
char[] ans=new char[50];
String strtemp;
File ofile= new File("J:\\questions.txt");
BufferedInputStream bis= null;
FileInputStream fis= null;
DataInputStream dis=null;
int ii=0;
int score=0;
System.out.println(eq[1] + "\n" + ea[1] + "\n" + eb[1] + "\n" + ec[1] + "\n" + ed[1] + "\n" + "\n" + "Answer: ");
String strans=x.nextLine();
char y=strans.charAt(0);
if(y==ans[1]){
score++;
}else{
}
try{
fis=new FileInputStream(ofile);
bis=new BufferedInputStream(fis);
dis=new DataInputStream(bis);
while(dis.available()!=0){
eq[1]=dis.readLine(); ea[1]=dis.readLine();
eb[1]=dis.readLine(); ec[1]=dis.readLine();
ed[1]=dis.readLine(); strtemp=dis.readLine();
ans[1]=strtemp.charAt(0);
}
bis.close();
dis.close();
fis.close();
}catch(FileNotFoundException e){
e.printStackTrace();
}catch(IOException e){
e.printStackTrace();
}
}