简体   繁体   English

在 /resources 下生成 txt 文件并立即读取它而无需重新构建应用程序

[英]Generate txt file under /resources and immediatelly read it without rebuilding the app

I have a rather simple question.我有一个相当简单的问题。 I have a controller with two endpoints我有一个带有两个端点的 controller

/newFile
/downloadFile/{fileName}

/newFile endpoint creates a simple .txt file under resources /newFile端点在资源下创建一个简单的.txt文件

and my expectation would be to hit /downloadFile/{fileName} and download the newly created resource.我的期望是点击/downloadFile/{fileName}并下载新创建的资源。

Resource res = new ClassPathResource(fileName);

so as it turned out classpath resource looks under build/resources and the file is not yet there (because I haven't restarted/rebuild the app, once I do it - I can download the file) but the whole idea is to dynamically generate files and access them immediately - is there a quick way to bypass this without having to rebuild?所以事实证明类路径资源在build/resources下看起来并且文件还不存在(因为我还没有重新启动/重建应用程序,一旦我这样做 - 我可以下载文件)但整个想法是动态生成文件并立即访问它们 - 有没有一种快速的方法可以绕过它而无需重建?

I too had the same problem when I was working on FACE Recognition API which has the same process of creating a file and and uploading it to analysis.我在处理 FACE Recognition API 时也遇到了同样的问题,它具有相同的创建文件并将其上传到分析的过程。

What java does is It abstracts project to JVM and runs on it, So your newly created file won't be in the JVM, What you need to do is to use a Database or any cloud storage or NFS. java 所做的是将项目抽象到 JVM 并在其上运行,因此您新创建的文件不会在 JVM 中,您需要做的是使用数据库或云存储或 NFS。

According to my perspective Using Database is the best option.根据我的观点,使用数据库是最好的选择。 Code Java How to upload files to database with Servlet, JSP and MySQL and Javatpoint store file in Oracle database are some documents you can refer for using a database. Code Java How to upload files to database with Servlet, JSP and MySQL and Javatpoint store file in Oracle database are some documents you can refer for using a database.

you can refer to this document for implementing your project.您可以参考此文档来实施您的项目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM