Results 1 to 3 of 3
  1. #1
    Canime is offline Member
    Join Date
    Mar 2011
    Posts
    2
    Rep Power
    0

    Default 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?

  2. #2
    subith86 is offline Senior Member
    Join Date
    Jan 2011
    Location
    Bangalore, India
    Posts
    102
    Rep Power
    0

    Default

    Quote Originally Posted by Canime View Post
    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.
    You are right. StringBuilder is a good option.

    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.

  3. #3
    Canime is offline Member
    Join Date
    Mar 2011
    Posts
    2
    Rep Power
    0

    Default

    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?

Similar Threads

  1. can't open a .jar file
    By demichelis89 in forum Java Applets
    Replies: 46
    Last Post: 10-25-2010, 11:45 AM
  2. Replies: 0
    Last Post: 03-05-2010, 04:21 AM
  3. Different Files Open in File -> Open Workspace
    By mgm2010 in forum JCreator
    Replies: 0
    Last Post: 04-11-2009, 02:14 PM
  4. Open File
    By JavaLerner in forum SWT / JFace
    Replies: 5
    Last Post: 07-12-2008, 06:41 PM
  5. To open an image file such as Jpeg file using JAva Program
    By itmani2020 in forum Advanced Java
    Replies: 10
    Last Post: 07-11-2008, 09:57 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •