How to copy large file with 4bits Encryption using java without get OutOfMemoryError: Java heap space error

问题描述 投票:0回答:0

我正在使用下面的代码通过在文件内容前后添加加密 2 位来复制文件(12 fileContent 34)。

但是,如果我复制 500mb 文件,它会抛出 'OutOfMemoryError: Java heap space error'。 这里的问题是通过在文件内容之后添加加密 2bits 来复制文件

我们有什么方法可以通过在内容中前后添加4位加密来逐口复制文件。

如果代码级别需要任何更改,请提供帮助。

String InputLocation = path+filename;      
InputStream fileStream = new FileInputStream(InputLocation);

byte[] fileStreamByteArray = fileStream.readAllBytes();

//Encryption Logic (**fileStreamByteArray**)
int bytesint = Math.toIntExact(fileStreamByteArray.length);
byte[] ss = ByteBuffer.allocate(2).putInt(bytesint).array();

byte[] encryptedFileByteArray = ByteBuffer.allocate(ss.length+BlobContent.length+ss.length)
                    
                     .put(ss)
          
                     .put(BlobContent)
        
                     .put(ss)
          
                     .array(); 

//OUTPUTSTREAM 
String OutputLocation = Epath+filename;   
OutputStream os = new FileOutputStream(OutputLocation);   
os.write(encryptedFileByteArray);   
os.close();```
java io out-of-memory heap-memory
© www.soinside.com 2019 - 2024. All rights reserved.