首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >访问云环境中的本地文件

访问云环境中的本地文件
EN

Stack Overflow用户
提问于 2017-02-16 20:01:27
回答 1查看 40关注 0票数 0

我正在尝试访问GeoLiteCity文件,它在我的本地计算机上工作,但无法获取云上的路径(Azure)。文件保存的层次结构如下:

代码语言:javascript
复制
/src/main/resources/database/GeoLiteCity.dat

我的代码:

代码语言:javascript
复制
void getFile() {
    if (this.file == null) {
        try {
            URL url =  this.getClass().getClassLoader().getResource("database/GeoLiteCity.dat");
            this.file = new File(url.toURI());
            System.out.println(file.getPath().toString());

        } catch (Exception ex) {
            System.out.println(file.getPath().toString(),ex);
        }
    }
}
EN

回答 1

Stack Overflow用户

发布于 2017-02-20 15:39:44

假设代码是运行在Tomcat上的Java的一部分。根据我的经验,如果您想通过this.getClass().getClassLoader().getResource("<the data file path relative to the root classes path>")方法获取资源,请确保webapps/<your-webapp-name>/WEB-INF/classes/database/路径下的数据文件GeoLiteCity.dat

如果你的WebApp部署在Azure WebApp上,我想你可以尝试在Azure webapp上使用数据文件的绝对路径,比如D:/home/site/wwwroot/webapps/<your-webapp-name>/<the data file path>,并且只使用new File("<the absolute path of data file>")

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42273386

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档