从目录中进行邮政编码并在春季下载而不创建新文件或目录
我有一个示例目录,称为'sample-directory'
(在资源中),其中包含文件和目录。
这是我的终点:
public void downloadZipFile(@RequestBody final Parameters parameter, final HttpServletResponse response) throws FileReadingException, IOException, URISyntaxException {
response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
response.setHeader(CONTENT_DISPOSITION, HEADER_VALUE_STR);
response.setStatus(HttpServletResponse.SC_OK);
this.generateZipService.generateZipFile(parameter, response);
}
在我的this.generatezipservice.generatezipfile(参数,resposne)方法中,我想从'sample-directory'
中读取所有文件目录(包括其中的所有目录和文件,包括更改)。
有人可以建议我还是给出指导我该怎么做?
我想在不创建新文件或目录的情况下这样做。
这样:
for all files {
if(currentFile is "TEST1.xml") {
change first Line here;
}
if(currentFile is "TEST2.xml") {
change second Line here;
}
}
Then zip full directory and download.
我也不想使用/src/main/resources
或类似的路径。 相反,我正在使用getClass()。getClassLoader()。getResource(“ folderDirectlyInsideresources/otherepackages/file.txt”);
我已经开始通过:
FileOutputStream fout = new FileOutputStream("src/main/resources/generate.zip");
ZipOutputStream zout = new ZipOutputStream(fout);
File folder = new File("src/main/resources/docker-compose-zip");
File[] listOfFiles = folder.listFiles();
for (File file : listOfFiles) {
ZipEntry ze = new ZipEntry(file.getName());
zout.putNextEntry(ze);
zout.closeEntry();
}
zout.close();
但是它下载它generate.zip files.zip文件,不是不是zip(也许是.txt格式)。但是我正在使用mediatype.application_octet_stream_value
I have a sample directory called 'sample-directory'
(in resources) with files and directories in it.
this is my endpoint:
public void downloadZipFile(@RequestBody final Parameters parameter, final HttpServletResponse response) throws FileReadingException, IOException, URISyntaxException {
response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
response.setHeader(CONTENT_DISPOSITION, HEADER_VALUE_STR);
response.setStatus(HttpServletResponse.SC_OK);
this.generateZipService.generateZipFile(parameter, response);
}
In my this.generateZipService.generateZipFile(parameter, resposne) method, I want to read all files from 'sample-directory'
, change some files here and download a zip file from this directory(includng all directories and files in it, including changes).
Can someone suggest me or give direction how can I do this?
I want to do it without creating new files or directories.
like this:
for all files {
if(currentFile is "TEST1.xml") {
change first Line here;
}
if(currentFile is "TEST2.xml") {
change second Line here;
}
}
Then zip full directory and download.
Also I don't want to use /src/main/resources
or paths like that.
instead I'm using getClass().getClassLoader().getResource("folderDirectlyInsideResources/otherPackages/file.txt");
I have started implementing this by:
FileOutputStream fout = new FileOutputStream("src/main/resources/generate.zip");
ZipOutputStream zout = new ZipOutputStream(fout);
File folder = new File("src/main/resources/docker-compose-zip");
File[] listOfFiles = folder.listFiles();
for (File file : listOfFiles) {
ZipEntry ze = new ZipEntry(file.getName());
zout.putNextEntry(ze);
zout.closeEntry();
}
zout.close();
but it downloads generate.zip file which is not zip(it is .txt format maybe). But I'm using MediaType.APPLICATION_OCTET_STREAM_VALUE
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论