I'm calling java code through a channel in flutter. It works, but when I try to read I file it does not find the file and throws me an exception. I've tried with all kind of routes but it simply does not find the file, here's my file structure:
And the code that I'm using for fetching the file is:
public class MainActivity extends FlutterActivity {
private static final String CHANNEL = "prueba/cien";
@Override
public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) {
GeneratedPluginRegistrant.registerWith(flutterEngine);
new MethodChannel(flutterEngine.getDartExecutor().getBinaryMessenger(), CHANNEL)
.setMethodCallHandler(
(call, result) -> {
if(call.method.equals("main")){
try {
ArrayList<String> sintomas = call.argument("sintomas");
ArrayList<String> signos = call.argument("signos");
ArrayList<ArrayList<String>>[] resultado = main(sintomas,signos);
result.success(resultado);
} catch (IOException e) {
e.printStackTrace();
}
}
}
);
}
private ArrayList<ArrayList<String>>[] main(ArrayList<String> sintomas,ArrayList<String> signos) throws IOException {
dataReader dr = new dataReader("texts/enfermedadPaciente.txt");
dataReader dr2 = new dataReader("texts/enfermedadPaciente.txt");
}
}
The reader class constructor is:
public class dataReader{
public dataReader(String path){
this.file = new File(path);
try{
this.br = new BufferedReader(new FileReader(file));
}
catch (FileNotFoundException ex){
System.out.println("File not found in "+path);
}
}
}