4
I have TXT file, and it lies like this:
01 02 03;
01 02 04;
01 03 04;
02 03 04;
Well, I upload this file on ArrayList<String>
as it is in the code below. How do I pass it to ArrayList<Integer>
, to manipulate your content?
package bola;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class LerArquivo {
public static ArrayList<String> lista = new ArrayList<>();
public void leitura() throws FileNotFoundException {
String path = "D:\\Conteudo\\teste.txt";
BufferedReader br = null;
FileReader fr = null;
try {
fr = new FileReader(path);
br = new BufferedReader(fr);
List<String> minhaList = new ArrayList<String>();
String line = br.readLine();
String[] meuArray = null;
while (line != null) {
line = br.readLine();
minhaList.add(line);
meuArray = minhaList.toArray(new String[0]);
}
for(int i = 0; i < meuArray.length; i++) {
System.out.println(meuArray[i]);
}
} catch (IOException e) {
System.out.println("Error: " + e.getMessage());
} finally {
try {
if (br != null)
br.close();
if (fr != null)
fr.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
public static void main(String[] args) throws IOException {
LerArquivo le = new LerArquivo();
le.leitura();
}
}
thanks for the solution.
– Silva