JAVA中如何读取src下所有的properties文件

JAVA中如何读取src下所有的properties文件,第1张

1使用javautilProperties类的load()方法

示例

//文件在项目下。不是在包下!!

InputStream in = new BufferedInputStream(new FileInputStream("demoproperties")) ;

Properties p = new Properties();

pload(in) ;

String className2 = pgetProperty("databasedriver");

String url = pgetProperty("databaseurl");

String user = pgetProperty("databaseuser");

String password = pgetProperty("databasepass");

2 使用javautilResourcebundle类的getbundle()方法

//前面没有“/”代表当前类的目录

示例:

//文件和类在同一个包下,注意它的文件名和后缀!!是调换的,

ResourceBundle resource = ResourceBundlegetBundle("propertiesjdbc");

String className = resourcegetString("databasedriver");

String url = resourcegetString("databaseurl");

String user = resourcegetString("databaseuser");

String password = resourcegetString("databasepass");

3使用javautilPropertyResourceBundle类的构造函数

示例:

// 文件在项目下  或者  src/demoproperties

//  在 src/demoproperties  写成 new FileInputStream("src/demoproperties")

InputStream in = new BufferedInputStream(new             FileInputStream("demoproperties"));

ResourceBundle rb = new PropertyResourceBundle(in) ;

String className4 = rbgetString("databaseurl");

4使用class变量的getresourceasstream()方法

示例:

InputStream in =PropertiesclassgetResourceAsStream("/properties/jdbcproperties");

// 包点类名下的。

// 如果找不到带有该名称的资源,则返回 null

Properties p = new Properties();

pload(in);

Systemoutprintln(pgetProperty("databaseurl"));

5使用classgetclassloader()所得到的javalangclassloader的getresourceasstream()方法 

// properties 文件 要放在src下面,否则找不到啊

示例:        

InputStream in = 类名classgetClassLoader()getResourceAsStream("jdbcproperties");

Properties p = new Properties() ;

pload(in);

Systemoutprintln(pgetProperty("databasepass"));

6使用javalangclassloader类的getsystemresourceasstream()静态方法  

示例:

// 同包名下

InputStream in = ClassLoadergetSystemResourceAsStream("properties/jdbcproperties");

Properties p = new Properties() ;

pload(in) ;

Systemoutprintln(pgetProperty("databaseuser"));

总结:如果是 在WEB上读取properties文件,写成下面这种。上面写的那些只在 JavaSE 中

String path = ThreadcurrentThread()getContextClassLoader()getResource("")getPath();

Systemoutprintln(path);

InputStream in = new FileInputStream(new File(path+Fileseparator+"mysqlproperties"));

Properties prop = new Properties();

是的,您可以使用<sourcesrc>标签来加载flv视频。这个标签可以让您在HTML文件中指定一个外部视频文件,并且可以指定视频文件的格式。您可以使用<sourcesrc>标签来加载flv格式的视频文件,并且可以指定视频文件的宽度和高度,以及其他一些参数,这样就可以在网页中播放flv格式的视频文件了。

以上就是关于JAVA中如何读取src下所有的properties文件全部的内容,包括:JAVA中如何读取src下所有的properties文件、<sourcesrc标签>可以加载.flv的视频吗、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/9617398.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-30
下一篇2023-04-30

发表评论

登录后才能评论

评论列表(0条)

    保存