这个就直接上demo了,主要用了Properties类
twerp.propertiest
username=testuser@tongtool.com
password=testuser
package com.debug;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
import bsh.This;
public class test1 {
@Test()
@Parameters({"param1"})
public void Test1(String param1) {
System.out.println(param1);
}
public void Test2() throws IOException {
Properties pro = new Properties();
InputStream in = new BufferedInputStream(new FileInputStream("twerp.properties")); //文件读取到内存中
pro.load(in); //加载内容
String name=pro.getProperty("username"); //通过key获取value
System.out.println(name);
}
public static void main(String[] args) throws IOException {
test1 t1 = new test1();
t1.Test2();
}
}