本帖最后由 Hueihuea 于 2021-8-1 19:40 编辑
SoundsJsonGo 简单 省事
你会不会因为懒得写sounds.json而烦恼?
使用SoundsJsonGo 一键生成sounds.json
使用方法:
将本jar和sounds文件夹放到同一目录在该路径打开命令窗口
输入java -jar SoundsJsonGo.jar
然后sounds.json就会自动生成在该目录下
注意:
请不要有中文名、空格、“/”等非法字符命名的文件夹或文件。
本软件生成的sounds.json是简单 甚至呆板的 所以更细节的配置依旧需要手动编辑
附下载和源码
SoundsJsonGo.jar
(2.18 KB, 下载次数: 11)
源码(就一个类)
- package mchhui.soundsjsongo;
- import java.io.BufferedWriter;
- import java.io.File;
- import java.io.FileOutputStream;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.io.OutputStream;
- import java.util.ArrayList;
- import java.util.List;
- public class SoundsJsonGo {
- public static void main(String[] args) {
- File file = new File("./sounds");
- if (!file.exists()) {
- throw new Error("Not Found Sounds Folder.找不到sounds文件夹");
- }
- ArrayList<String> soundsList = new ArrayList<String>();
- findFileList(file, soundsList, "");
- String json = "";
- json += "{\n";
- for (int i = 0; i < soundsList.size(); i++) {
- String name = soundsList.get(i);
- json += " "" + name.replaceAll("/", ".") + "": {\n";
- json += " "sounds": [\n";
- json += " " + "{\n";
- json += " " + ""name": "" + name + "",\n";
- json += " " + ""stream": true";
- json += "\n" + " " + "}";
- json += "\n ]";
- json += "\n }";
- if (i != soundsList.size() - 1) {
- json += ",\n";
- }
- System.out.println("add "+name);
- }
- json += "\n}";
- File outFile = new File("./sounds.json");
- if(!outFile.exists()) {
- try {
- outFile.createNewFile();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- try {
- BufferedWriter bufferedWriter=new BufferedWriter(new FileWriter(outFile));
- bufferedWriter.write(json);
- bufferedWriter.close();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- System.out.println("已输出到目录下sounds.json");
- }
- public static void findFileList(File dir, List<String> fileList, String preName) {
- if (!dir.exists() || !dir.isDirectory()) {
- return;
- }
- String[] files = dir.list();
- for (int i = 0; i < files.length; i++) {
- File file = new File(dir, files[i]);
- if (file.isFile()) {
- fileList.add(preName + file.getName().replace(".ogg", ""));
- } else {
- findFileList(file, fileList, preName + file.getName() + "/");
- }
- }
- }
- }
复制代码 |
效果:
来自群组:
CNPC Script Studio