Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/322.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
Rx java 使用Vert.x和RxJava读取行_Rx Java_Rx Java2_Vert.x - Fatal编程技术网

Rx java 使用Vert.x和RxJava读取行

Rx java 使用Vert.x和RxJava读取行,rx-java,rx-java2,vert.x,Rx Java,Rx Java2,Vert.x,我正在使用Vert.x文件系统API读取属性文件,需要对其进行一些转换。问题是文件不是逐行读取,而是作为单个块读取。 假设我有这个属性文件: name=abc name=def 使用此代码: vertx.fileSystem().rxReadFile("/path/file.properties") .map(buffer -> buffer.toString()) .subscribe(data -> { System.ou

我正在使用Vert.x文件系统API读取属性文件,需要对其进行一些转换。问题是文件不是逐行读取,而是作为单个块读取。 假设我有这个属性文件:

name=abc
name=def
使用此代码:

vertx.fileSystem().rxReadFile("/path/file.properties")
        .map(buffer -> buffer.toString())
        .subscribe(data -> {
            System.out.println(">"+data);
        }, err -> System.out.println("Cannot read the file: " + err.getMessage()));
我打印的是一块数据:

>name=abc
name=def
由于我必须在每一行上执行转换,因此我预计会出现以下情况:

>name=abc
>name=def

您只需替换此行:

.map(buffer -> buffer.toString())
作者:


上面的代码将按换行符分割缓冲区,并逐行向流发送。

谢谢您的回复。我会选择第一种解决方案,但是在这种情况下,“缓冲区”是未定义的。通过使用
.flatMap(buffer->Observable.fromArray(buffer.toString().split(“\n”))
也不会编译,因为它不符合SingleSource,我也尝试了第二种解决方案,但我没有任何.collect方法可从
vertx.fileSystem()获得.rxReadFile
抱歉,我以为
vertx.fileSystem().rxReadFile
返回的是可观察的,但它返回的是单个。我更新了我的答案
.flatMapObservable(buffer -> Observable.fromArray(buffer.toString().split("\n")))