【问题标题】:what is the maximum size can i write into outputstream in java我可以在java中写入输出流的最大大小是多少
【发布时间】:2015-02-24 07:39:45
【问题描述】:

我的 Web 应用程序有一个要求,即从 db 下载数据为 csv,而不在服务器中创建物理文件。所以我决定直接写入 outputstreame。

那么我可以写入 OutputStream 的最大数据字节数是多少。

我的代码如下所示。

   StreamingOutput stream = new StreamingOutput() {
                @Override
                public void write(OutputStream os) throws IOException, WebApplicationException {
                    try {
                        -----------some code------
                         while(rs.next){
                            os.write(rs.getString(0).getBytes()+","+rs.getString(1).getBytes());
                         }

                        os.close();
                    } catch (Exception e) {
                        throw new WebApplicationException(e);
                    }
                }
            };

【问题讨论】:

  • 这取决于您的 OutputStream 实现、您的 JVM 配置等。
  • @Andy Turner 如果我将 2^32 -1 个字符写入输出流对象并仍在写入... os.write(2^32-1 chars); os.write(jshjaskjf);
    如何增加尺寸?
  • 它是一个,所以它不会在任何地方存储字节。您可以继续写入超过 2^32 个字节。
  • @laune 但我需要通过网络上的 REST 服务发送它。
  • 那只是一个架构类。您需要确定您应该使用的 API。因此,正如您的问题所说,这不是“将字节写入流”。

标签: java rest csv download outputstream


【解决方案1】:
import java.util.*;
import java.io.*;

公共类 BigFile{ public static void main(String asd[]){

        String fileString = "D:/INSAn/error.log";
        try {
            BigFile bigFile = new BigFile(fileString);
            for (String line : bigFile)
                System.out.println("line : " + line);

        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            System.out.println("exception");
        }
    }
}
Hey you can use the above code , it will read file of any size.I tested it for 1 GB file.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-14
    • 2021-10-12
    • 1970-01-01
    • 1970-01-01
    • 2020-08-28
    相关资源
    最近更新 更多