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 :)