I use this code snippet to get the file as input stream. The version.txt file is packaged in my jar application, in the topmost folder.
InputStream resource = getClass().getClassLoader().getResourceAsStream("version.txt");
It works almost all the time. But for one user, he picks up another version.txt file, which is not in my bank. How can I guarantee that this downloads the specific version.txt file that is in my bank?
" ", ? , , JAR , , version.txt, Java , .
version.txt
, JAR , version.txt , , :
com.yourcompany.yourproject.version
, :
Stream resource = getClass().getClassLoader().getResourceAsStream("com/yourcompany/yourproject/version/version.txt");
- -.
, , , . (, log4j, ), , .
version.txt , . com.myapp( ),
getClass().getClassLoader().getResourceAsStream("com/myapp/version.txt");
the code snippet will use the class loader loading this class to find the version.txt file. if the file exists in the class path used by the class loader in more than one place, it may return the wrong file (depending on the order of the class path).
Source: https://habr.com/ru/post/1718898/More articles:How to apply Msi conversion when deleting? - windows-installerWebRequest.Create throws "The value cannot be null. Parameter name: str" exception - .netRunning an IIS Application with Different User Credentials - securityHow does program C generate this output? - cOne tinyMCE instance moved between multiple text areas? - jqueryHow to write Perl constructor in XS? - perlTable cell with image too large in IE - htmlhttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1718901/how-can-i-get-proc-report-in-sas-to-show-values-in-an-across-variable-that-have-no-observations&usg=ALkJrhiGNuOp-9YEExPLYcRO1HXoVS69UAHow do you use the Java Caching System (JCS) resource through multiple EJBs - cachingLost in the maze of Visual Studio? - .netAll Articles