from file to array java

Solutions on MaxInterview for from file to array java by the best coders in the world

showing results for - "from file to array java"
Valery
26 Jan 2018
1BufferedReader bufferedReader = new BufferedReader(new FileReader(myfile));
2String []data;
3data = new String[10]; // <= how can I do that? data = new String[lines.size]
4
5for (int i=0; i<lines.size(); i++) {
6    data[i] = abc.readLine();
7    System.out.println(data[i]);
8}
9abc.close();
Kyara
07 Sep 2016
1ArrayList<String> result = new ArrayList<>();
2 
3try (BufferedReader br = new BufferedReader(new FileReader(filename))) {
4    while (br.ready()) {
5        result.add(br.readLine());
6    }
7}
8
Camilla
20 Jan 2016
1BufferedReader abc = new BufferedReader(new FileReader(myfile));
2List<String> lines = new ArrayList<String>();
3
4while((String line = abc.readLine()) != null) {
5    lines.add(line);
6    System.out.println(data);
7}
8abc.close();
9
10// If you want to convert to a String[]
11String[] data = lines.toArray(new String[]{});