给每一行文本加‘‘,的方法

-- 2024 10 23 午 阳光

--sql中如果要查字段内容需要加'', 有时候文本没有 加单引号和逗号,可以使用这种方式如下

import java.io.*;
import java.nio.file.*;

public class JsonQuoteAdder {
    public static void addQuotesToJsonLines(String inputFilePath, String outputFilePath) throws IOException {
        Path inputPath = Paths.get(inputFilePath);
        Path outputPath = Paths.get(outputFilePath);

        try (BufferedReader reader = Files.newBufferedReader(inputPath);
             BufferedWriter writer = Files.newBufferedWriter(outputPath)) {

            String line;
            while ((line = reader.readLine()) != null) {
                writer.write("'" + line + "',");
                writer.newLine();
            }
        }
    }

    public static void main(String[] args) {
        try {
            addQuotesToJsonLines("G:\\XXXX\\XXXX.json", "G:\\XXXX\\XXXXX2.json");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

这样,每行内容都会被包裹在单引号中,并且后面会跟上一个逗号。