每次创建文件时,我都希望它在带有文件名的新文件夹中进行。
public void convertLocalSwaggerToAsciiDoc() throws IOException {
File folder = new File("C:\\Users\\jeff\\Desktop\\apidocs\\apidocs\\SwaggerJSON");
File[] listOfFiles = folder.listFiles(); //Makes an array of all the files
int index, length = lengthOfFiles(listOfFiles); //lengthOfFiles counts number of files inside the folder
for (index = 0; index < length ; index++) {
Swagger2MarkupConverter.from(listOfFiles[index].getPath()).build().intoFolder("src/docs/asciidoc/generated/conversion");
}
}
答案 0 :(得分:2)
如果我正确阅读您的问题/陈述,您似乎想要创建不同的文件夹。
在Java中,这可以通过创建文件实例来实现 -
File file = new File("path to new folder");
然后致电 -
file.mkdir();
实现新目录的创建。
**编辑**
迭代地,做这样的事情 -
for (each file in the list) {
File folder = new File(path to parent folder + file.getName())
folder.mkdir();
File file = new File(folder.getPath() + currentFileName + currentFileExtension);
}