`
wandejun1012
  • 浏览: 2720431 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

propertiesfile

    博客分类:
  • java
 
阅读更多

config.properties放在根目录。

 

写文件:

package com.mkyong.common;
 
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;
 
public class App 
{
    public static void main( String[] args )
    {
    	Properties prop = new Properties();
 
    	try {
    		//set the properties value
    		prop.setProperty("database", "localhost");
    		prop.setProperty("dbuser", "mkyong");
    		prop.setProperty("dbpassword", "password");
 
    		//save properties to project root folder
    		prop.store(new FileOutputStream("config.properties"), null);
 
    	} catch (IOException ex) {
    		ex.printStackTrace();
        }
    }
}

 

读文件:

package com.mkyong.common;
 
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;
 
public class App 
{
    public static void main( String[] args )
    {
    	Properties prop = new Properties();
 
    	try {
               //load a properties file
    		prop.load(new FileInputStream("config.properties"));
 
               //get the property value and print it out
                System.out.println(prop.getProperty("database"));
    		System.out.println(prop.getProperty("dbuser"));
    		System.out.println(prop.getProperty("dbpassword"));
 
    	} catch (IOException ex) {
    		ex.printStackTrace();
        }
 
    }
}
 

 

 

 

 

 

 

 

 

分享到:
评论

相关推荐

    Project has no default.properties file! 解决方案

    ### Project has no default.properties file! 解决方案 #### 背景介绍 在进行Android项目的开发过程中,有时候会遇到从其他地方导入项目的情况。如果在导入的过程中遇到“Project has no default.properties file!...

    eclipse plugin i18n properties file editor

    eclipse plugin i18n properties file editor http://blog.csdn.net/yuanfei_1988 link安装方式 可直接编译i18n国际化文件

    properties file editor

    "Properties File Editor" 是一个专为编辑Java属性文件(.properties)设计的工具。在Java开发中,.properties文件常用于存储配置信息,如国际化文本、应用设置等。这款编辑器旨在提供更高效、便捷的方式来管理和...

    tf_import_as_klayout_lyp-master.zip

    "tf_import_as_klayout_lyp-master.zip"这个压缩包是为了帮助用户将工艺库的layer properties file(.lyp)导入到Klayout,以便更好地理解和分析GDSII文件。 首先,理解.KLAYOUT_LYP文件:这是Klayout特有的层属性...

    HrisLoginUsing.PropertiesFile

    标题"HRISLoginUsing.PropertiesFile"表明这是一个关于人力资源信息系统(HRIS)登录功能的实现,它利用了`Properties`文件来管理用户的登录凭证或者相关配置。 `Properties`文件是Java中的一个标准格式,通常以`....

    Eclipse I18N Properties File Editor-开源

    Eclipse I18N Properties File Editor 是一个专为 Java 国际化(i18n)设计的开源插件,它极大地简化了对 `.properties` 文件的管理和编辑工作。`.properties` 文件是 Java 应用程序中用于存储本地化字符串和其他...

    Properties file changer:用户可以使用该项目更改属性文件-开源

    标题中的“Properties file changer”指的是一个项目,它的主要功能是让用户能够方便地修改属性文件。在Java编程中,属性文件通常以`.properties`为扩展名,用于存储应用程序的配置信息,如数据库连接字符串、系统...

    JSP/Servlet Properties file changer:此项目有助于编辑应用程序中的属性文件-开源

    标题中的“JSP/Servlet Properties file changer”是一个项目,它允许用户通过JSP(Java Server Pages)前端界面来编辑应用程序中的属性文件。属性文件在Java应用程序中常常用于存储配置信息,如数据库连接字符串、...

    Android代码-ServeStream

    1.) To compile ServeStream using Ant, you must specify where your Android SDK and NDK are located via the local.properties file. To generate a local.properties file run the following command from the ...

    ConvertYamlAndProperties-1.0.5

    ConvertYamlAndProperties-1.0.5

    怎样读取properties文件内容

    public static Properties loadProperties(String propertiesFile) throws Exception { Properties props = null; InputStream in = null; try { // 创建FileInputStream实例,传入properties文件路径 in = ...

    在eclipse中安装properties插件PropertiesEditor

    在右侧的“File types”列表中找到“*.properties”,然后查看“Associated editors”区域,你应该能看到“Properties Editor”已被添加。 5. **设置默认编辑器**:为了使Properties Editor成为默认编辑器,点击...

    eclipse中安装properties插件

    安装完成后,你可以创建新的`.properties`文件,或者右键点击已有的文件,选择`Open With` -> `Properties File Editor`。这个编辑器会提供诸如自动换行、语法高亮、错误检查、中文友好显示等功能。同时,它还支持...

    eclipse编辑properties文件的插件

    一个知名的例子是"Properties File Editor"插件,它为`.properties`文件提供了以下功能: 1. **语法高亮**:突出显示关键字和字符串,提高代码可读性。 2. **编码支持**:支持不同的字符编码,如UTF-8,确保国际化...

    properties 文件的插件

    例如,Eclipse IDE有一个名为"Properties File Editor"的内置插件,它提供了语法高亮、自动缩进、键值对自动完成等功能,极大地提高了开发效率。在Visual Studio Code中,可以安装如"Property List"这样的第三方插件...

    properties类封装

    - 保存 properties 文件:使用 `Properties.store()` 方法将属性写入输出流,例如 `props.store(new FileOutputStream("config.properties"), "Properties file description");` - 获取和设置属性:使用 `...

    eclipse 属性文件编辑器插件

    在处理Java项目时,我们经常需要编辑属性文件(Properties files),这些文件用于存储应用的配置信息或本地化文本。"eclipse PropertiesEditor"是一款专为Eclipse设计的属性文件编辑器插件,它提供了一个更友好、...

    java读写xxx.properties文件实用小例

    props.store(fos, "Comment for the properties file"); fos.close(); ``` **更新`.properties`文件** 更新文件通常涉及读取、修改和重新写入。你可以先读取文件,然后使用`setProperty()`方法更改或添加新的...

    java操作properties文件

    props.store(output, "Properties file updated"); } catch (IOException io) { io.printStackTrace(); } finally { if (output != null) { try { output.close(); } catch (IOException e) { e....

    Jenkins 使用INJECTOR插件实现修改环境变量(亲测实用)

    在 Job 配置的“构建后操作”(Post-build Actions)中,选择“Inject environment variables”(Inject environment variables)插件选项,勾选“Use properties file from build”(Use properties file from build),...

Global site tag (gtag.js) - Google Analytics