使用Properties类对文件进行读写操作.
1条回答 默认 最新
- 昏晓错星辰 2017-04-04 08:38关注
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Properties;public class PropertiesDemo {
public static void main(String[] args) throws FileNotFoundException, IOException {
Properties prop=new Properties();
prop.load(new FileReader("config.properties"));
System.out.println(prop.getProperty("username"));
System.out.println(prop.getProperty("password"));
File file=new File("config.propertires");
System.out.println(file.getAbsolutePath());
}
}
其中newFileReader里面写的是java中类加载的目录解决 无用评论 打赏 举报