黑马程序员技术交流社区

标题: 利用Properties存放文件中的数据 [打印本页]

作者: z6528328    时间: 2015-9-21 00:04
标题: 利用Properties存放文件中的数据
自己的代码,与大家分享
  1. package test;
  2. import java.io.*;
  3. import java.util.*;
  4. /**
  5. *@author wangkun
  6. */

  7. public class test3 {
  8.     public static void main(String[] args ) throws IOException{
  9.     info();
  10.     }
  11.     public static void info() throws IOException{
  12.     //建立一个test文件的输入缓存流bf
  13.         BufferedReader bf =new BufferedReader(new FileReader("d:\\test.txt"));

  14.         Properties p =new Properties();
  15.         //将缓存流载入到p中
  16.         String line = null;
  17.             while((line = bf.readLine())!=null){
  18.             //将数据以"="分割
  19.                 String[] args = line.split("=");
  20.                 //sop(args[0]);
  21.                 //sop(args[1]);
  22.                 //输入到p中
  23.                 p.setProperty(arr[0],arr[1]);
  24.         }
  25.         bf.close();
  26.     }
复制代码








欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2