Open file for reading.
What is the simplest method, i.e. The bare minimum to open a file, read it to a string and then close the file?
Also, what is the best way to store the strings that are coming in? For example I read from another site that you can just add new lines to the StringBuilder class. For example, would ArrayList<String> be the best way to do that?
Finally, if I am to read a series of characters rather than the string, how can I process all that while I have the file open... ie hasNext() something?
So, what is the easiest method?
You are right. StringBuilder is a good option.
Originally Posted by Canime
ArrayList is better option if your requirement is to add lines. I said better because if in your requirement you need to get the 2nd line, then it's not so easy with StringBuilder. But it ArrayList you can easily do it using indexes.
I tried all these methods, they seem really slow compared to the C or C++ comparisons. There seems like a lot of initiation involved in doing this... Hmm nothing really easy such as the freopen() in c++ that I have been using?