Results 1 to 7 of 7
  1. #1
    2potatocakes is offline Member
    Join Date
    Sep 2008
    Posts
    43
    Rep Power
    0

    Default Need your thoughts on the best way to store/save/send a VERY large string

    Hi all,

    I'm just wondering what your thoughts are guys on a recommended way for me to play with a String of numbers that is incredibly large?

    I'm talking a String of numbers 100,000,000 digits+ long with no spaces. Obviously, I realise I can break it up into several seperate files and just write a method to join them but I am wondering if anybody can recommend any other file formats or anything along those lines, rather than using txt files that I could use?

    I only need to be able to have access to the Strings, modify them where necessary and then save them again in the same format.

    Also because of the size, I was wondering, should I be converting to Hexidecimal to save space?

    Can anybody point me in a direction?

    Thanks in advance ;)

  2. #2
    angryboy's Avatar
    angryboy is offline Senior Member
    Join Date
    Jan 2009
    Posts
    742
    Rep Power
    6

    Default

    converting it to hex? i'm guessing you don't plan to edit the file directly, but only use it for storage?

    why not use java.math.BigInteger and BigDecimal, it holds values as large as your ram. (or so I've heard.)
    USE CODE TAGS--> [CODE]...[/CODE]
    Get NotePad++ (free)

  3. #3
    2potatocakes is offline Member
    Join Date
    Sep 2008
    Posts
    43
    Rep Power
    0

    Default

    To be honest, I'm just about to finish Uni so I've had about 2 and 1/2 years of study of this, but the only times we've ever saved data, in any form, we've saved it in a txt file and then just accessed it again the next time we've used the program.

    My program actually performs the same functions as the BigInteger and BigDecimal classes, but I've created my own method for doing so using a mathematical algorithm I've created. Basically it is just a program that manipulates the characters of a string in a particular way. So I'm not looking to use BigInteger or BigDecimal.

    I'm really just trying to find out other methods of saving Strings of data. I've touched on XML which looks ok but what I'm wondering is: How do video games and programs save files so that you can load them the next time you're on and pickup where you started. I know they don't use txt files... ;)

    Any ideas?

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Some actually do use text files. I think that M$ Word uses XML, some use serialization,... have I left anything out (I'm sure that I have)?

  5. #5
    2potatocakes is offline Member
    Join Date
    Sep 2008
    Posts
    43
    Rep Power
    0

    Default

    never heard of serialization, I'll look it up. Thanks heaps Fubarable!
    I don't mind using text files.. I just need the data that they hold to be uneditable to users that just stumble across the file. I want only my program to be able to edit the files.

  6. #6
    Steve11235's Avatar
    Steve11235 is offline Senior Member
    Join Date
    Dec 2008
    Posts
    1,046
    Rep Power
    7

    Default

    There is nothing wrong with plain text files. You could also use a database, but that doesn't sound appropriate from what you have said.

    Unless you need to have the entire series of digits available for your algorithm, you should read the file using an input stream and deal with it in chunks. Read a chunk, modify it, write the chunk, loop.

    If you are manipulating each digit as a byte, you can also cut your file sizes in half by using byte streams. char streams use two bytes. Also, byte streams have less overhead, since a char stream starts as a byte stream and then does additional processing.

  7. #7
    xcallmejudasx's Avatar
    xcallmejudasx is offline Senior Member
    Join Date
    Oct 2008
    Location
    Houston, TX & Flint, MI
    Posts
    609
    Rep Power
    7

    Default

    I'm actually doing a similar project for class(creating a LongInteger class that is essentially big integer).

    Sorry I've broken my glasses so I have issues reading on this monitor. You're wanting to store numbers with upto 100 million digits? I don't think serialization is the way to go with this since you would really just be serializing that it is a String and then saving all those digits after it. I think your best bet is to convert it to some more manageable base format or just break it up into different parts.
    Liberty has never come from the government.
    Liberty has always come from the subjects of government.
    The history of liberty is the history of resistance.
    The history of liberty is a history of the limitation of governmental power, not the increase of it.

Similar Threads

  1. How can i save the data Internally(auto save)
    By Rama Koti Reddy in forum AWT / Swing
    Replies: 2
    Last Post: 11-01-2010, 08:31 PM
  2. how to store an ArrayList<string> into cookies?
    By perplexingtrax in forum Java Servlet
    Replies: 7
    Last Post: 01-12-2009, 12:30 AM
  3. Code too large for try statement
    By vravindran in forum JavaServer Pages (JSP) and JSTL
    Replies: 2
    Last Post: 01-09-2009, 11:49 AM
  4. Store String Tokenizer o/p onto an array
    By rajchief in forum New To Java
    Replies: 1
    Last Post: 08-08-2008, 09:00 PM
  5. I would then store a string...
    By susan in forum AWT / Swing
    Replies: 1
    Last Post: 08-07-2007, 04:15 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
  •