-1

How would you rad a textfile that is a bunch of seven letter words back to back into an ArrayList. EX: flowersflowersflowersflowersflowersflowers

I need to read them into the ArrayList as a single column. EX: Flowers flowers flowers flowers

The words are not all the same, I just used flowers as an example, all of the words in the textfile are different.

A little little bit of additionally info, I dont know how many words are in the textfile I'm trying to read into the ArrayList.

Any help/example of code would be awesome!

ControlAltDel
  • 33,923
  • 10
  • 53
  • 80
cding001
  • 7
  • 3

1 Answers1

0

this should work.

File myFile = new File("data.txt");
BufferedReader readBuffer = new BufferedReader(new FileReader(myFile));

ArrayList<String> myArrayList = new ArrayList<String>();

String line = null;
while ((line = readBuffer.readLine()) != null) {
    while (line.length() > 0) {
        myArrayList.add(line.substring(0,6);
        line = line.substring(7);
    }
}

readBuffer.close();
SLeptons
  • 17
  • 3