Results 1 to 1 of 1
  1. #1
    SeanC is offline Member
    Join Date
    Aug 2010
    Posts
    24
    Rep Power
    0

    Smile Best way to solve this encryption file handling problem.

    Hi all, I'm writing a simple encryption algorithm and have stumbled upon a problem relating to the file handling itself.

    What my program does is reads text from a file, encrypts it, and writes it to another file. That's all well and good, and it works fine - until a large file is used for input. I tested it with a 30MB file and 300MB file, and got an 'out of memory error - no space on heap' or something like that.

    I imagine that this is caused due to the way I'm handling the file.

    To solve it, I decided to use a BufferedReader to read a character at a time using the 'read()' method. After the character is read, it is encrypted and then written to a file using the BufferedWriter's 'write()' method.

    This method works for large files (i tested it on a 300MB file, and although it took around 2 minutes to finish; it worked).

    My main concern is that like this, the harddisk is constantly being accessed for every single character - I'm sure it's highly inefficient.

    Can anyone suggest something I can do to improve efficiency? Please note that when I used 'readLine()' instead of 'read()', i got the java heap error, so im guessing i have to read a character at a time.

    Also, i cannot post code as this is for an assignment - just some guidelines/suggestions would suffice and would be greatly appreciated :)

    Query also posted here: http://www.daniweb.com/forums/post14...ml#post1424250
    Last edited by SeanC; 12-22-2010 at 11:34 PM.

Similar Threads

  1. file handling problem
    By gcampton in forum Eclipse
    Replies: 19
    Last Post: 01-05-2010, 01:18 PM
  2. WebService encryption problem
    By falnik in forum Advanced Java
    Replies: 3
    Last Post: 07-26-2009, 04:21 AM
  3. Recursive File List - Help me problem solve please
    By caps_lock in forum New To Java
    Replies: 17
    Last Post: 01-14-2009, 06:44 PM
  4. Encryption-Decryption Problem
    By dinesh.1.sharma in forum Advanced Java
    Replies: 1
    Last Post: 07-17-2008, 10:03 PM
  5. Problem in File Handling in Java
    By getbiplab in forum New To Java
    Replies: 6
    Last Post: 03-31-2008, 12:02 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
  •