内存不足的错误的文件,虽然使用大块的上传超过3MB更大 [英] out of memory error for files greater than 3Mb though upload using chunk

查看:155
本文介绍了内存不足的错误的文件,虽然使用大块的上传超过3MB更大的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

double bytes = file.length();
                                    double kilobytes = (bytes / 1024);  
                                    double megaBytes = (kilobytes/1024);


                                if(megaBytes<10)
                                {
                                    filesize = Double.toString(kilobytes);
                                    System.out.println("kilobytes String : " + filesize);
                                    try
                                    {
                                        arrByteFile = null;

                                        int bytesRead;
                                        int bufferSize = 1024;
                                        FileInputStream is = new FileInputStream(file);
                                        ByteArrayOutputStream bos = new ByteArrayOutputStream();
                                        byte[] b = new byte[bufferSize];

                                        while ((bytesRead = is.read(b)) != -1) 
                                        {
                                            bos.write(b, 0, bytesRead);
                                        }

                                        arrByteFile = bos.toByteArray();
                                        is.close();

                                        System.out.println("File byte array Size:-"+arrByteFile.length);
                                    }
                                    catch(Exception e)
                                    {
                                        e.printStackTrace();
                                    }


                                    try 
                                    {
                                        ChunkOfByteArray chunkOfByteArray = new ChunkOfByteArray(arrByteFile);
                                        arrayList = chunkOfByteArray.getChunksOfByteArray();
                                    } 
                                    catch (Exception e)
                                    {
                                        // TODO Auto-generated catch block
                                        e.printStackTrace();
                                    }

如何处理内存不足的错误??

how to handle out of memory error??

反正是有上传大文件中的Base64格式..?

is there anyway to upload large file in Base64 format ..??

我使用AQuery罐子API调用和使用块上传文件。但它而只有创造块给出错误。

i am using AQuery jar for API calls and using chunks to upload file. but it gives error while creating chunks only.

感谢您的时间。

推荐答案

问题是当你读它,你不发送数据。您正在创建一个大的缓冲区,不帮你,因为在所有的文件可以在一个去,如果你需要这种读取,但你不知道。

The problem is you are not sending the data as you read it. You are creating a large buffer which doesn't help you at all because a file can be read in one go if you needed this, but you don't.

就像你读它,你不会为较大的文件使用更多的内存发送数据。即而不是写入 BOS 直接写入套接字输出流。

Just send the data as you read it and you won't use more memory for larger files. I.e. instead of writing to bos write straight to the socket output stream.

BTW您可以使用Base64的,但是这是更大的,并会使用更多的内存(除非你发送的数据,你读它,因为我的建议)

BTW You can use Base64, but this is larger and would use more memory (unless you sent the data as you read it as I suggested)

这篇关于内存不足的错误的文件,虽然使用大块的上传超过3MB更大的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆