Results 1 to 1 of 1
- 12-22-2010, 11:32 PM #1
Member
- Join Date
- Aug 2010
- Posts
- 24
- Rep Power
- 0
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#post1424250Last edited by SeanC; 12-22-2010 at 11:34 PM.
Similar Threads
-
file handling problem
By gcampton in forum EclipseReplies: 19Last Post: 01-05-2010, 01:18 PM -
WebService encryption problem
By falnik in forum Advanced JavaReplies: 3Last Post: 07-26-2009, 04:21 AM -
Recursive File List - Help me problem solve please
By caps_lock in forum New To JavaReplies: 17Last Post: 01-14-2009, 06:44 PM -
Encryption-Decryption Problem
By dinesh.1.sharma in forum Advanced JavaReplies: 1Last Post: 07-17-2008, 10:03 PM -
Problem in File Handling in Java
By getbiplab in forum New To JavaReplies: 6Last Post: 03-31-2008, 12:02 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks