Results 1 to 14 of 14

Thread: What would be the fastest way to read from a file?

  1. #1
    Senior Member
    Join Date
    Feb 2005
    Location
    Folsom, CA
    Posts
    221
    Thanks
    0
    Thanked
    0 times in 0 posts

    What would be the fastest way to read from a file?

    Would it be to use an ArrayList and store everything in it? Or use a StringBuffer and store everything in it? Or do we read in character by character? What I am trying to achieve is the fastest possible way to read in large or small files basically.

    Thanks in advance.

  2. #2
    Senior Members' Member Matt1eD's Avatar
    Join Date
    Feb 2005
    Location
    London
    Posts
    2,462
    Thanks
    0
    Thanked
    0 times in 0 posts
    • Matt1eD's system
      • Motherboard:
      • MSI K9N6SGM-V GeForce 6100
      • CPU:
      • Athlon 64 LE-1620 2.41GHz
      • Memory:
      • 2 GB DDR2
      • Storage:
      • 1.25 TB
      • Graphics card(s):
      • Onboard
      • PSU:
      • eBuyer Extra Value 500W!
      • Operating System:
      • XP Pro
    Do you then want to be able to write to it aswell?

  3. #3
    Senior Member
    Join Date
    Feb 2005
    Location
    Folsom, CA
    Posts
    221
    Thanks
    0
    Thanked
    0 times in 0 posts
    Hmm...well...yes and no. Suppose one situation we dont need to write back. Another situation we do. How would then reading impact writing?

  4. #4
    Senior Members' Member Matt1eD's Avatar
    Join Date
    Feb 2005
    Location
    London
    Posts
    2,462
    Thanks
    0
    Thanked
    0 times in 0 posts
    • Matt1eD's system
      • Motherboard:
      • MSI K9N6SGM-V GeForce 6100
      • CPU:
      • Athlon 64 LE-1620 2.41GHz
      • Memory:
      • 2 GB DDR2
      • Storage:
      • 1.25 TB
      • Graphics card(s):
      • Onboard
      • PSU:
      • eBuyer Extra Value 500W!
      • Operating System:
      • XP Pro
    What language are you in?

  5. #5
    Senior Member Kezzer's Avatar
    Join Date
    Sep 2003
    Posts
    4,863
    Thanks
    12
    Thanked
    5 times in 5 posts
    Java obviously. Need more info though, are you storing/reading/writing multiple files? I use ArrayLists and have used StringBuffer's before, both very nice features. I use my ArrayList to store objects, it's very easy to use

  6. #6
    HEXUS.net Webmaster
    Join Date
    Jul 2003
    Location
    UK
    Posts
    3,108
    Thanks
    1
    Thanked
    0 times in 0 posts
    Kezzer it may be obvious to you but not to others, there's no need to be condescending. Also all you've done is given your preference, not the reasons for them. It might help suryad if you can expand on your comments after all he can't justify his decision to anyone else by saying "some guy on a forum said he preferred ArrayLists"

    Suryad, a quick google search here (http://www.google.co.uk/search?q=Jav...en-US:official) uncovers a lot of good material e.g. http://forum.java.sun.com/thread.jsp...82408&start=15

  7. #7
    Senior Member
    Join Date
    Feb 2005
    Location
    Folsom, CA
    Posts
    221
    Thanks
    0
    Thanked
    0 times in 0 posts
    Its my bad. I should have specified what language I am in. I apologize.

    As for specifics regarding what I am doing is writing a simple XML editor from scratch using the JDOM API. So far I have gotten the GUI up completely, and I have been able to open an xml file in the GUI and have it show up as an InternalFrame in the DesktopPanel component. I also have been able to generate a simple Tree describing the structure of the xml document. I have also been able to validate the xml document for well formedness as well as validate it against its schema. Now I want to be able to modify the xml document, save, edit, revalidate, so on both in the text editor as well as by manipulating the JTree. So while file IO is not as intensive, I still want the fastest possible solutions to whatever I am doing. Try to make my code as intensive as possible.

    On another note I have been working on this project in Netbeans, and that has taught me a lot about how to use the IDE and I must say I am getting very comofortable with using it. There are some features I would like to be implemented into Netbeans and it seems like the way things are going for that IDE they will probably get implemented in the next release!

    Iain thanks for the links. I will check it out give a feedback as soon as I can. If you guys are interested I would be willing to post my source code for your perusal. This is an open source proj. I dont know who will use it but I think it is a good exercise in my Java skills. I am just a month old university graduate after all hehe.
    Last edited by suryad; 29-04-2005 at 05:48 PM.

  8. #8
    Senior Member Kezzer's Avatar
    Join Date
    Sep 2003
    Posts
    4,863
    Thanks
    12
    Thanked
    5 times in 5 posts
    Quote Originally Posted by Iain
    Kezzer it may be obvious to you but not to others, there's no need to be condescending. Also all you've done is given your preference, not the reasons for them. It might help suryad if you can expand on your comments after all he can't justify his decision to anyone else by saying "some guy on a forum said he preferred ArrayLists"

    Suryad, a quick google search here (http://www.google.co.uk/search?q=Jav...en-US:official) uncovers a lot of good material e.g. http://forum.java.sun.com/thread.jsp...82408&start=15
    eh? i wasn't being condescending at all! grrr, damn text based conversation misinterpretation. Nah sorry, i didn't mean to be condescending i should have put a smiley face in there or something

  9. #9
    Senior Member
    Join Date
    Oct 2003
    Posts
    2,069
    Thanks
    4
    Thanked
    7 times in 3 posts
    Might not be java...
    If s/he doesnt know much could be anything really?
    In C just read in character by character and store in array
    Twigman

  10. #10
    Large Member
    Join Date
    Apr 2004
    Posts
    3,720
    Thanks
    47
    Thanked
    99 times in 64 posts
    He did mention ArrayList and StringBuffer though Kinda points to the obvious. But anyway, i'm sure there are loads of tutorials and forum threads on this topic all over the web, search google.
    To err is human. To really foul things up ... you need a computer.

  11. #11
    Senior Member Kezzer's Avatar
    Join Date
    Sep 2003
    Posts
    4,863
    Thanks
    12
    Thanked
    5 times in 5 posts
    Quote Originally Posted by yamangman
    He did mention ArrayList and StringBuffer though Kinda points to the obvious. But anyway, i'm sure there are loads of tutorials and forum threads on this topic all over the web, search google.
    That's what i was going to refer to but then it'd seem like i'm trying to be even more mean. They're both features of the Java API

  12. #12
    Senior Members' Member Matt1eD's Avatar
    Join Date
    Feb 2005
    Location
    London
    Posts
    2,462
    Thanks
    0
    Thanked
    0 times in 0 posts
    • Matt1eD's system
      • Motherboard:
      • MSI K9N6SGM-V GeForce 6100
      • CPU:
      • Athlon 64 LE-1620 2.41GHz
      • Memory:
      • 2 GB DDR2
      • Storage:
      • 1.25 TB
      • Graphics card(s):
      • Onboard
      • PSU:
      • eBuyer Extra Value 500W!
      • Operating System:
      • XP Pro
    Java eh, tis on my list to learn over the summer holidays

  13. #13
    Senior Member
    Join Date
    Feb 2005
    Location
    Folsom, CA
    Posts
    221
    Thanks
    0
    Thanked
    0 times in 0 posts
    Looks like reading in a file sequentially is the best way to do it. Line by line or character by character methinks.

  14. #14
    Sam
    Sam is offline
    Registered+
    Join Date
    Oct 2003
    Posts
    22
    Thanks
    0
    Thanked
    0 times in 0 posts
    Just use a BufferedReader to read it in line by line putting it into a string builder (or buffer if you're on pre 1.5).

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 63
    Last Post: 14-11-2011, 09:17 AM
  2. Batch file & copy query
    By Fatboy in forum Help! Quick Relief From Tech Headaches
    Replies: 4
    Last Post: 25-04-2005, 03:42 PM
  3. Nero or Burner ?
    By Foxile in forum Help! Quick Relief From Tech Headaches
    Replies: 30
    Last Post: 04-04-2005, 07:31 AM
  4. How do you backup?
    By Howard in forum PC Hardware and Components
    Replies: 48
    Last Post: 05-01-2005, 09:05 AM
  5. Manage downloaded webpages file and folder
    By Zathras in forum Software
    Replies: 0
    Last Post: 17-09-2003, 05:37 PM

Posting Permissions

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