Properties中的load方法主要是建立Properties与输出流之间的关联。

原a.txt中的内容为:
模拟Properties中的load函数

代码:

import java.io.BufferedReader;
import java.io.FileReader;
import java.util.Properties;

public class Demo2 {

	public static void main(String[] args) throws Exception {

		Properties prop=new Properties();
		//一行一行的读
		BufferedReader bfr=new BufferedReader(new FileReader("a.txt"));

		String line=null;
		while((line=bfr.readLine())!=null){
			if(line.startsWith("#")){//以'#'开头的不要
				continue;
			}
			String[] strs=line.split("=");//以'='作为分割
			prop.setProperty(strs[0], strs[1]);
			
		}
		prop.list(System.out);//将结果显示在控制台上
	}

}

输出结果为:
模拟Properties中的load函数

相关文章:

  • 2022-12-23
  • 2021-11-19
  • 2022-02-21
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-10-12
  • 2022-12-23
  • 2021-10-17
  • 2021-11-11
  • 2022-12-23
  • 2022-02-09
  • 2021-12-04
相关资源
相似解决方案