Results 1 to 1 of 1
- 12-23-2010, 12:32 AM #1Member
- Join Date
- Aug 2010
- Rep Power
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-23-2010 at 12:34 AM.
- By gcampton in forum EclipseReplies: 19Last Post: 01-05-2010, 02:18 PM
- By falnik in forum Advanced JavaReplies: 3Last Post: 07-26-2009, 05:21 AM
- By caps_lock in forum New To JavaReplies: 17Last Post: 01-14-2009, 07:44 PM
- By dinesh.1.sharma in forum Advanced JavaReplies: 1Last Post: 07-17-2008, 11:03 PM
- By getbiplab in forum New To JavaReplies: 6Last Post: 03-31-2008, 01:02 PM