I am working on an AES 256 bit File encryption tool. The way it works now is by:
reading an entire file into a String,
encrypting the string,
deleting the old file, then outputting the encrypted String into the old File object.
This works for small Files, but if you were to try to encrypt a Large file, such as one larger than the Heap Space java has access too, you receive errors. Long story short, how can i read the file one MB at a time, as a String, encrypt that string, then write that MB to a temp file? This would allow for large files to be encrypted.
No need for temp files. Just use File Streams (FileInputStream and FileOutputStream). Streaming I/O was exactly created for processing long files in chunks. You can use FileReader/Writer if you want to read/write strings. There is an example: