Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.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 8中使用Consumer在文件中编写映射_Java_Collections_Java 8_Consumer - Fatal编程技术网

在Java 8中使用Consumer在文件中编写映射

在Java 8中使用Consumer在文件中编写映射,java,collections,java-8,consumer,Java,Collections,Java 8,Consumer,我想编写一个类MapWriter,它实现了Map的消费者,将输入映射写入文本文件。我有一个最终属性outputFilePathStr @AllArgsConstructor public class MapWriter<T> implements Consumer<Map<T,Integer>>{ private final String outputFilePathStr; @Override public void accept

我想编写一个类
MapWriter
,它实现了
Map
的消费者,将输入映射写入文本文件。我有一个最终属性outputFilePathStr

@AllArgsConstructor
public class MapWriter<T> implements Consumer<Map<T,Integer>>{

    private final String outputFilePathStr;

    @Override
    public void accept(Map<T, Integer> tIntegerMap) {
        Files.write(outputFilePathStr, tIntegerMap);
    }
}
@allargsconstuctor
公共类MapWriter实现使用者{
私有最终字符串outputFilePathStr;
@凌驾
公共无效接受(映射tIntegerMap){
write(outputFilePathStr、tIntegerMap);
}
}
我在Files.write(outputFilePathStr,tIntegerMap)中有一个错误,我无法编译它

附言:注释
@allargsconstuctor

来自Lombok插件,它自动生成所有构造函数。

我解决了它。我改变了这一点:

 Files.write(outputFilePathStr, tIntegerMap.toString().getBytes())

“我有一个错误”…不要用这么多的信息压倒我们。方法
文件没有过载。write
接受
java.util.Map
作为参数:查看文件中负责写入数据的可用方法。例如,看起来很有希望。您只需要将映射转换为字符串,这样就可以将其用作
CharSequence csq
参数。如果文件已经存在并且包含一些数据,您还想做什么?您想在文件末尾追加新数据(作为新行)还是删除旧数据并替换为新数据。请不要发布代码、错误等图像。请将格式正确的信息复制/粘贴到您的问题中。