Monday, April 15, 2019

Get data from properties file by File Input Stream and File Reader

 package muttutest;  
 import java.io.File;  
 import java.io.FileInputStream;  
 import java.io.FileReader;  
 import java.util.Properties;  
 public class SysProps {  
      static Properties properties, properties2;  
      public static void main(String[] args) throws Exception {  
           File file = new File(  
                     "C:\\Users\\Mutturaj\\workspace\\maven-learn\\src\\test\\java\\muttutest\\muttu.properties");  
           //File Input Stream  
           FileInputStream inStream = new FileInputStream(file);  
           properties.load(inStream);  
           System.out.println(properties.getProperty("name"));  
           //File reader  
           FileReader fileReader = new FileReader(  
                     "C:\\Users\\Mutturaj\\workspace\\maven-learn\\src\\test\\java\\muttutest\\muttu.properties");  
           properties2=new Properties();  
           properties2.load(fileReader);  
           System.out.println(properties2.getProperty("name"));  
      }  
 }  

No comments:

Post a Comment