简体   繁体   English

我可以写位于类路径的文件吗

[英]Can i write file located at classpath

I want to write a text file at classpath.我想在类路径中编写一个文本文件。 want to make some changes in that file.想对该文件进行一些更改。

this is spring boot application and packaging it as a jar.这是 Spring Boot 应用程序并将其打包为 jar。 So basically this text file is located in jar & I want to make changes to that file.所以基本上这个文本文件位于 jar 中,我想对该文件进行更改。

Don't know it is possible or not.不知道有没有可能。

but please suggest to me how I can do that?但请建议我如何做到这一点?

Files inside a jar can be read from (called resource files in general).可以读取 jar 中的文件(通常称为资源文件)。

You cannot modify them directly though.但是您不能直接修改它们。 For that, you need them to be outside the jar.为此,您需要将它们放在罐子外面。

Possible duplicate of Updating resource files at runtime 在运行时更新资源文件的可能重复

If it is a .properties file though, there are ways to do it.如果它是一个 .properties 文件,有办法做到这一点。
Following blog seems helpful ( https://crunchify.com/java-properties-files-how-to-update-config-properties-file-in-java/ )以下博客似乎有帮助( https://crunchify.com/java-properties-files-how-to-update-config-properties-file-in-java/

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

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