Java:正在从 Json 文件中删除内容

Java: Removing content from Json file

我想知道如何 remove/empty 一个 .json 文件。

我在网上找到了各种方法,如何清空一个 JSON Objekt,但是给出的 Objekt 是在同一个文件中定义和完成的

我想要的:访问一个 .json 文件并删除所有 content/empty 对象。

我怎样才能做到这一点? Filepath

编辑 @Sagar Kharab the Errors

您可以简单地截断文件或用“{}”覆盖它。

File file = new File(Paths.get("Path to your file").toString());
file.setWritable(true);
BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(Paths.get("Path to your file").toString()));
bufferedOutputStream.write("{}".getBytes());
bufferedOutputStream.flush();

我认为这对你有用。