0
I need tips on how to create (where to start, what functions to use, etc).
A generic project that receives a file .txt
, read the data and store the words in a ArrayList<>
.
I’ve already created a framework for:
- Upload a file
.txt
( within the project ) through theinput
of user; - Read the file data;
I have no idea how to take the information from this '.txt' and apply it to the ArrayList<>
.
Code :
public static void main(String[] args) {
Scanner ler = new Scanner(System.in);
System.out.printf("Informe o nome de arquivo texto:\n");
String nome = ler.nextLine();
System.out.printf("\nConteúdo do arquivo texto:\n");
try {
FileReader arq = new FileReader(nome);
BufferedReader lerArq = new BufferedReader(arq);
String linha = lerArq.readLine(); // lê a primeira linha
while (linha != null) {
System.out.printf("%s\n", linha);
linha = lerArq.readLine(); // lê da segunda até a última linha
}
arq.close();
} catch (IOException e) {
System.err.printf("Erro na abertura do arquivo: %s.\n",
e.getMessage());
}
System.out.println();
}
You want to save each row of the file into one
ArrayList
?– Zulian
How’s the line of that file? Do you want to simply play the full line within the position of an Array? or wants to divide it and do some treatment?
– Henrique Santiago
So I’m doing in parts, first precious just play the line, then I start doing the treatment, using the comma as a separator.
– Lucas Silva