一:如果容器为Websphere,那下面为红色的地方不能加"/",如果为tomcat,则加上"/",

  1. String  path = this.class.getResource("").getPath()+"config.properties";
  2. Properties properties= new Properties();
  3. properties.load(new FileInputStream(new File(path )));

如果你的config.properties在某个包下面,则把包同时带上,如:config.properties在com.df.util包下,则为:

  1. String  path = this.class.getResource("").getPath()+"com/df/util/config.properties";
  2. Properties properties= new Properties();
  3. properties.load(new FileInputStream(new File(path )));

二:如果你的项目中用到了spring,那么也可这样获取,

  1. import org.springframework.core.io.Resource;
  2. import org.springframework.core.io.ClassPathResource;
  3. Resource resource = new ClassPathResource("config.properties");  //直接读取src下的,位于class文件之下
  4. Properties  properties= new Properties();
  5. InputStream in = resource.getInputStream();
  6. properties.load(in);

Websphere中获取项目下.properties路径的更多相关文章

  1. java如何从一段html代码中获取图片的src路径

    java如何从一段html代码中获取图片的src路径 package com.cellstrain.icell.Test; import java.util.ArrayList;import java ...

  2. Spring MVC中获取当前项目的路径

    Spring MVC中获取当前项目的路径 在web.xml中加入以下内容 <!--获取项目路径--> <context-param> <param-name>web ...

  3. IOS中获取各种文件的路径介绍及方法

    IOS中获取各种文件的目录路径的方法 技术交流新QQ群:414971585 iphone沙箱模型的有四个文件夹,分别是什么,永久数据存储一般放在什么位置,得到模拟器的路径的简单方式是什么. docum ...

  4. [C#]中获取当前程序运行路径的方法

    获取当前程序运行路径: ①//获取当前 Thread 的当前应用程序域的基目录,它由程序集冲突解决程序用来探测程序集.string str = System.AppDomain.CurrentDoma ...

  5. 定时发布任务,在global.asax中获取文件的物理路径的方法

    如果要把一个相对路径或者虚拟路径映射道服务器的物理路径,通常会使用Server.MapPath()函数,比如将根目录下的html目录映射为物理路径:Server.MapPath("html& ...

  6. Asp.Net Core 中获取应用程序物理路径(Getting the Web Root Path and the Content Root Path in ASP.NET Core)

    如果要得到传统的ASP.Net应用程序中的相对路径或虚拟路径对应的服务器物理路径,只需要使用使用Server.MapPath()方法来取得Asp.Net根目录的物理路径,如下所示: // Classi ...

  7. Java代码中获取配置文件(config.properties)中内容的两种方法

    方法千千万,本人暂时只总结了两种方法. (1)config.properties中的内容如图 在applicationContext.xml中配置 <!-- 引入配置文件 --> < ...

  8. [转] ASPNET Core 中获取应用程序物理路径

    如果要得到传统的ASP.Net应用程序中的相对路径或虚拟路径对应的服务器物理路径,只需要使用使用Server.MapPath()方法来取得Asp.Net根目录的物理路径,如下所示: // Classi ...

  9. .Net Core api 中获取应用程序物理路径wwwroot

    如果要得到传统的ASP.Net应用程序中的相对路径或虚拟路径对应的服务器物理路径,只需要使用使用Server.MapPath()方法来取得Asp.Net根目录的物理路径,如下所示: // Classi ...

随机推荐

  1. hadoop学习day3 mapreduce笔记

    1.对于要处理的文件集合会根据设定大小将文件分块,每个文件分成多块,不是把所有文件合并再根据大小分块,每个文件的最后一块都可能比设定的大小要小 块大小128m a.txt 120m 1个块 b.txt ...

  2. centos7.3下apache搭建django[未成功]

    1 apache肯定已经按照完毕了, 如果没有  yum install httpd yum install mod_wsgi 安装完成之后,mod_wsgi.so会在Apache的modules目录 ...

  3. MySQL GTID (三)

    五.如何跳过一个GTID 环境见系列一 5.1 创建表,模拟数据 #主机上 create table t_test (id int primary key ,name varchar(10)); in ...

  4. The web application [/zzti] registered the JDBC driver [com.microsoft.sqlserver.jdbc.SQLServerDriver

    先说下题目:因为是在我进行处理项目升级时同时遇到了上面的问题,一般都会遇到,所以就一并说了 不罗嗦了,正题: 在本地服务器中提供tomcat6,然后在myeclipse中配置severs tomcat ...

  5. Ssm框架常见报错

    错误1: The origin server did not find a current representation for the target resource or is not willi ...

  6. 54. Spiral Matrix (Graph)

    Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral or ...

  7. Stop单个Coroutine

    public Coroutine StartCoroutine(string methodName, object value = null); Description Starts a corout ...

  8. 3-java_string学习笔记:

    java中String的常用方法

  9. Laravel trait 使用心得

    trait 是在PHP5.4中为了方便代码复用的一种实现方式,但目前我在看的的PHP项目中较少看的有程序员去主动使用这个实现方式,在laravel中有很多 trait 的使用,关于trait 在 la ...

  10. abp AutoMap Custom Mapping

    [DependsOn(typeof(AbpAutoMapperModule))] public class MyModule : AbpModule { public override void Pr ...