Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Spring批处理:读取txt文件并将所有行作为单个字符串返回给处理器_Java_Spring_Spring Batch - Fatal编程技术网

Java Spring批处理:读取txt文件并将所有行作为单个字符串返回给处理器

Java Spring批处理:读取txt文件并将所有行作为单个字符串返回给处理器,java,spring,spring-batch,Java,Spring,Spring Batch,我试图从Spring Batch中的文件中读取文本,但我需要所有行作为单个字符串到达.processor,而不是逐行。我在FlatFileItemReader中读到了关于.setRecordSeparatorPolicy。有没有其他方法可以做到这一点?也许是另一种读者或其他什么 任何帮助都将不胜感激 public ItemStreamReader<String> stringReader() throws IOException { Resources[] resources


我试图从Spring Batch中的文件中读取文本,但我需要所有行作为单个字符串到达
.processor
,而不是逐行。我在
FlatFileItemReader
中读到了关于
.setRecordSeparatorPolicy
。有没有其他方法可以做到这一点?也许是另一种读者或其他什么

任何帮助都将不胜感激

public ItemStreamReader<String> stringReader() throws IOException {
    Resources[] resources.. // load files here
    MultiResourceItemReader<String> reader = new MultiResourceItemReader<String>();
    reader.setResources(resources);
    reader.setDelegate(flatFileItemReader()); //sets FlatFileIteamReader

    return reader;
}

@Bean
public TaskletStep managerStep() throws Exception {
    return managerStepBuilderFactory.get("managerStep")
            .<String, String>chunk(6)
            .reader(stringReader())
            .processor(myProcessor()) //all lines as 1 String here per File
            .writer(doSomething())
            .build();
}
publicItemStreamReader stringReader()引发IOException{
资源[]资源..//在此处加载文件
MultiResourceItemReader=新的MultiResourceItemReader();
reader.setResources(resources);
reader.setDelegate(flatFileItemReader());//设置flatFileItemReader
返回读取器;
}
@豆子
public TaskletStep managerStep()引发异常{
返回managerStepBuilderFactory.get(“managerStep”)
.chunk(6)
.reader(stringReader())
.processor(myProcessor())//此处每个文件的所有行均为1个字符串
.writer(doSomething())
.build();
}

区块处理模型是为面向项目的用例设计的。如果您只有一项,我看不到使用面向块的步骤有任何附加值。简单的tasklet更合适。

哪个版本的java?Java8解决方案可以吗?然后简单地执行:
processor(String.join(“,”,myProcessor())//选择您自己的分隔符