java - 如何在多个文件夹中保存字符串 JSON 元素

标签 java json java.nio.file

我有一个包含 70 个对象的 JSON 文件,每个对象都包含数组等元素。以下是 JSON 对象的示例:

{ 
   "journal": ".....",
   "category": ["Sport", "football", "Real Madrid"],
   "abstract": "Here is an example"
} 

首先,我使用元素“category” 的字符串创建文件夹。下一步是根据元素 "abstract" 的字符串创建一个 .txt 文件。我要做的是将每个 .txt 文件保存在这些文件夹中。

例如,元素 "abstract" 包含字符串“Here is an example”,我使用此短语创建一个 .txt 文件,我想知道如何做我将其保存在文件夹 SportFootballReal Madrid 中。

最佳答案

这是一些 java 示例:

// create a list of folder names and call it "folderArray".
// You are already doing something like this, but I don't know the variable name.
// You also have the name of the abstract text file name in a variable.
// This code assumes that variable is called "abstractFileName".

for (final String folder : folderArray)
{
    final String newFileName = folder + File.separatorChar + abstractFileName;

    // create a file with the name "newFileName"

    // Write the abstract contents to the new file.
}

关于java - 如何在多个文件夹中保存字符串 JSON 元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36265926/

相关文章:

json - 基于 TCP 的 JSON 传输选择

java - Oracle 的 JDK zip 文件系统中的错误,您如何编写 SSCCE 来重现它?

java - 将 SCP 与 JSch 一起使用时如何转义双引号?

java - 用Java检测所有可用网络的广播地址

c# - 数组上的 LINQ to JSON 组查询

java.io.IOException : There are no more files - (when copying a pdf to another location)

java - 如何使用 Pig 检查 JSON 中缺少的 key ?

Java 从路径中删除了一个斜杠,后来给我 NoSuchFileException

java基本计算器查找星期几 7

java - 使用 UriBuilder 的 HATEOAS 链接