当我尝试使用windwos并成功写入文件并附加内容时,我需要编写文件并附加内容,但是当涉及到linux环境时,我看不到任何创建的文件,也没有错误或异常。
这就是我在 Windows 上写文件的方式
HashMap<String, Object> map = new Gson().fromJson(dynamicJson, HashMap.class);
String keys = map.keySet().stream().collect(Collectors.joining(", "));
String values = map.values().stream().map(obj ->
String.valueOf(obj)).collect(Collectors.joining(", "));
File file = new File("D:\\report-temp.csv");
try (FileWriter fw = new FileWriter("D:\\report-temp.csv", true);
BufferedWriter bw = new BufferedWriter(fw);
PrintWriter out = new PrintWriter(bw)) {
if (file.length() == 0) {
out.println(keys);
out.println(values);
} else {
out.println(values);
}
} catch (IOException e) {
}
Run Code Online (Sandbox Code Playgroud)
当我在 linux 上运行它时,我已经更改了文件位置,/home/xx/hashan/但是我没有在 linux 上创建文件。