欢迎访问悦橙教程(wld5.com),关注java教程。悦橙教程  java问答|  每日更新
页面导航 : > > 文章正文

java,

来源: javaer 分享于  点击 12775 次 点评:135

java,


获取输入栏地址

String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort();  
获取所有参数:request.getQueryString()。

获取当前项目根路径

System.getProperty("user.dir")

单例类

public class Singleton {
/*   private static Singleton instance = new Singleton(); //已经自行实例化

     private Singleton(){}  //私有的默认构造

     public static Singleton getInstance() { //静态工厂方法

      return instance; 

  } */
    private static Singleton instance = null;

    private Singleton(){}

    public static synchronized Singleton getInstance() {

   //也可以这样写:synchronized public static Singleton getInstance() {

        if (instance == null){

            instance = new Singleton();

       }

       return instance; 

    } 
}

读取properties

ResourceBundle bundle = ResourceBundle.getBundle(包名.文件名);//文件名不加后缀
String s = bundle.getString(文件里的键名);
---------------------------------------------------------------------------------------------------------------------
InputStream in = new BufferedInputStream(new FileInputStream(配置文件));//实例化出配置文件 
或者InputStream in =  ClassLoader.getSystemResourceAsStream("包名/文件名");//文件名加后缀
或者InputStream in =  本类类名.class.getClassLoader().getResourceAsStream("包名/文件名");//文件名加后缀
Properties p = new Properties(); 
p.load(in);
in.close();
p.getProperty(文件里的键名)

文件分隔符
File.separator

相关文章

    暂无相关文章
相关栏目:

用户点评