将项目迁移到 Servlet - 属性文件

发布于 2024-12-22 01:38:46 字数 338 浏览 1 评论 0原文

我正在将一个项目迁移到 servlet。 我将 jar 放在 lib 目录中,将编译后的类放在 classes 目录中。 但是,我正在应用程序中加载和读取一些文件(属性、wsdl 文件)。例如,这就是我加载属性的方式:

try {
    InputStream in = new BufferedInputStream(new FileInputStream("my.prop"));
    myConfig.load(in);
} catch (Exception e) {
    logger.error(e.getMessage(), e);
}

我正在加载的那些文件去了哪里?

I am migrating a project to a servlet.
I put the jars in the lib directory, the compiled classes in classes directory.
However, I have some files (properties, a wsdl file) that I am loading and reading in my application. For example this is how I am loading my properties:

try {
    InputStream in = new BufferedInputStream(new FileInputStream("my.prop"));
    myConfig.load(in);
} catch (Exception e) {
    logger.error(e.getMessage(), e);
}

Where do those files that I am loading go?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

桃扇骨 2024-12-29 01:38:46

它们通常直接进入类路径,这样您就不会依赖于本地磁盘文件系统的当前工作目录。但是您必须改变获取输入流的方式:

InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream("my.prop");

另请参阅:

They usually go straight in the classpath so that you aren't dependent on the current working directory of the local disk file system. But you've got to change the way how you're getting an inputstream:

InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream("my.prop");

See also:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文