⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 读写指定的属性文件演示.txt

📁 含有许多JAVA的技巧!
💻 TXT
字号:
读写指定的属性文件演示 
(加入日期:2002-3-21 点击数:1450)
【对此文发表评论】 【编程爱好者论坛】 【保存文章至硬盘】 【打印文章】 
 
代码:
import java.io.*;
import java.util.Properties;

public class PropertiesDemo {
  public static void main(String[] args)
  {
    String pFilename = System.getProperty("user.dir")
      + System.getProperty("file.separator") + "test.properties"; // 构造文件名
    Properties p = new Properties();  

    try
    {
      FileInputStream in = new FileInputStream(pFilename);  // 构造文件的输入流
      p.load(in);           // 读入属性
      in.close();
    }
    catch(Exception e)
    {
      System.out.println("Error of create input stream");
    }

    System.out.println(p.getProperty("property1"));
    p.setProperty("property1","new value"); // 给property1赋新的值

    try
    {
      FileOutputStream out = new FileOutputStream(pFilename);
      p.store(out,"This file is a test"); // 设置属性文件的文件头信息
      out.flush();
      out.close();
    }
    catch(Exception e)
    {
      System.out.println("Error of write input stream");
    }
  }
}

本栏文章均来自于互联网,版权归原作者和各发布网站所有,本站收集这些文章仅供学习参考之用。任何人都不能将这些文章用于商业或者其他目的。( ProgramFan.Com ) 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -