It is required to read xls file. But try is never executed, and the condition from catch is satisfied. As a result, bb = {β€œ0,0,0,0”}. I can not understand what I'm doing wrong. The file is in the project folder.

Moving the file to another location, changing the name did not give anything. I thought the thing was that it was xls, but even with txt it was the same.

Book bb = new Book(); String[] mas = bb.boob(); public class Book { public String[] data = new String[4]; public String[] boob() { try(FileInputStream fis = new FileInputStream("list.xls")) { //Workbook wb = new HSSFWorkbook(fis); for(int i=0; i<4; i++){ data[i] = "1"; } fis.close(); return data; } catch (IOException e){ String[] d ={"0","0","0","0"}; return d;} } } 
  • four
    this is why IDEs automatically insert e.printStackTrace (); into a catch block that clearly states what the problem is. - WeNeedToGoDeeper
  • I think that the file is still not in the project folder. Check back. I tried, I tried to work. - iramm
  • Check where the program is looking for this file using System.out.println(new File("list.xls" ).getCanonicalPath()) . Miracles do not happen - if the file is not located, then it is not there. - Pavel Mayorov
  • one
    Problem on android? There is also no concept of "file in the project folder", everything is split into resources, etc. - zRrr
  • one
    Thank you all, I figured it out. It turns out you had to open the file using assets. For example, fis = getAssets (). Open ("list.xls"); Thank you all very much for helping me with: - MiniDi

1 answer 1

It was necessary to open the file using assets. For example, fis = getAssets (). Open ("list.xls");