Spring,FlatFileItemWriter写大文件

时间:2018-02-21 08:57:26

标签: java spring-boot

我需要使用FlatFileItemWriter编写一个大文件。 当我调用write方法时,会发生OutOfMemory 有没有办法写大文件? 我的作者定义如下:

FlatFileItemWriter<FieldSet> writer = new FlatFileItemWriter<>();
        File mostRecent = <myFile>
        FileSystemResource resource = new FileSystemResource(<myTmpFile>);

        FileUtils.deleteQuietly(resource.getFile());
        writer.setResource(resource);
        DelimitedLineAggregator<FieldSet> delimitedLine = new DelimitedLineAggregator<>();
        delimitedLine.setDelimiter(SEPARATOR);
        writer.setLineAggregator(delimitedLine);

        writer.setHeaderCallback(new FlatFileHeaderCallback() {
            public void writeHeader(Writer writer) throws IOException
            {
                StringBuffer buffer = new StringBuffer();
                for (Column column : Column.values())
                {
                    buffer.append(column.getName());
                    buffer.append(SEPARATOR);
                }
                writer.write(CHAR_FOR_EXCEL + buffer.toString());
            }
        });
        writer.open(new ExecutionContext());

        writer.write(items);

0 个答案:

没有答案