I would like the user to send an .xls file to the system and from that a database would be created. The method I have is working, however the parameter that the FileInputStream receives is a String indicating the path of the file. Only the system will be used by different machines and the file sent will have different paths.
What I would like to know is how do I get the user to choose from the machine the file that should be read by the system, rather than the system picking the file from a specific (static) path.
The method follows:
public void convertePlanilhaEmAlunos() {
try {
// ALTERAR O PATH DE ACORDO COM O LOCAL DA PLANILHA
FileInputStream file = new FileInputStream(
"C:\Users\Desktop\teste.xls");
// Get the workbook instance for XLS file
XSSFWorkbook workbook = new XSSFWorkbook(file);
// Get first sheet from the workbook
XSSFSheet sheet = workbook.getSheetAt(0);
Iterator<Row> rowIterator = sheet.iterator();
while (rowIterator.hasNext()) {
Row row = rowIterator.next();
if (row.getRowNum() < 7) {
continue;
}
for (@SuppressWarnings("unused")
Cell cell : row) {
aluno.setNome(String.valueOf(row.getCell(0)));
aluno.setDataNascimento(String.valueOf(row.getCell(1)));
aluno.setRg(String.valueOf(row.getCell(2)));
aluno.setNomeMae(String.valueOf(row.getCell(3)));
aluno.setRgMae(String.valueOf(row.getCell(4)));
aluno.setNomePai(String.valueOf(row.getCell(5)));
aluno.setCurso(String.valueOf(row.getCell(6)));
aluno.setTurma(String.valueOf(row.getCell(7)));
}
if (aluno.getNome() == "") {
break;
}
System.out.println(aluno.getNome());
criaAluno();
aluno = new Aluno();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}