BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
String str
while ((str =in.readLine()) != null)
{
items = str.split("\n");
}
in.close();
String (str) contains data from a text file like:
January
February
March
etc.
Each word is on ag new line.
I want to read the string and separate each word on a new line and store into an array of String objects (this would be the variable named ‘items’).
Actually,
BufferedReader.readLinealready splits the input based on newlines.So, where you currently have:
you only need to append
strto your array.For example, with the
infilefile holding:the following program outputs
6(the size of the array list created):