Monday, 6 March 2017

Java Tutorial: System class in java [How to modify the system property]


Click here to watch in Youtube :
https://www.youtube.com/watch?v=ZqkxXiSWxwI&list=UUhwKlOVR041tngjerWxVccw

Click the below Image to Enlarge
Java Tutorial: System class in java [How to modify the system property] 
myProperties.txt
name=Peter
email=peter@yahoo.com

PropertiesDemo.java
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

public class PropertiesDemo
{

    public static void main(String[] args) throws IOException
    {
        /*
         * Set up new properties object from file
         * "myProperties.txt"
         */
        FileInputStream fis = new FileInputStream("myProperties.txt");
        /*
         * This statement initializes the new properties
         * object, p, with the current set of system
         * properties
         */
        Properties p = new Properties(System.getProperties());
        p.load(fis);

        /*
         * To modify the existing set of system properties,
         * use System.setProperties. This method takes a
         * Properties object that has been initialized to
         * contain the properties to be set. This method
         * replaces the entire set of system properties with
         * the new set represented by the Properties object.         * 
         */
        System.setProperties(p);
        // display new properties
        System.getProperties().list(System.out);

    }
}
Output
-- listing properties --
java.runtime.name=Java(TM) SE Runtime Environment
sun.boot.library.path=C:\Java\jre1.8.0_111\bin
java.vm.version=25.111-b14
java.vm.vendor=Oracle Corporation
java.vendor.url=http://java.oracle.com/
path.separator=;
java.vm.name=Java HotSpot(TM) 64-Bit Server VM
file.encoding.pkg=sun.io
user.script=
user.country=US
sun.java.launcher=SUN_STANDARD
sun.os.patch.level=Service Pack 1
java.vm.specification.name=Java Virtual Machine Specification
user.dir=D:\eclipse\workspace\PropertiesDemo
java.runtime.version=1.8.0_111-b14
java.awt.graphicsenv=sun.awt.Win32GraphicsEnvironment
java.endorsed.dirs=C:\Java\jre1.8.0_111\lib\endorsed
os.arch=amd64
name=Peter
java.io.tmpdir=C:\Users\Ramesh\AppData\Local\Temp\
line.separator=

java.vm.specification.vendor=Oracle Corporation
user.variant=
os.name=Windows 7
sun.jnu.encoding=Cp1252
java.library.path=C:\Java\jre1.8.0_111\bin;C:\Windows\S...
email=peter@yahoo.com
java.specification.name=Java Platform API Specification
java.class.version=52.0
sun.management.compiler=HotSpot 64-Bit Tiered Compilers
os.version=6.1
user.home=C:\Users\Ramesh
user.timezone=
java.awt.printerjob=sun.awt.windows.WPrinterJob
file.encoding=Cp1252
java.specification.version=1.8
user.name=Ramesh
java.class.path=D:\eclipse\workspace\PropertiesDemo\bin
java.vm.specification.version=1.8
sun.arch.data.model=64
java.home=C:\Java\jre1.8.0_111
sun.java.command=PropertiesDemo
java.specification.vendor=Oracle Corporation
user.language=en
awt.toolkit=sun.awt.windows.WToolkit
java.vm.info=mixed mode
java.version=1.8.0_111
java.ext.dirs=C:\Java\jre1.8.0_111\lib\ext;C:\Windo...
sun.boot.class.path=C:\Java\jre1.8.0_111\lib\resources.ja...
java.vendor=Oracle Corporation
file.separator=\
java.vendor.url.bug=http://bugreport.sun.com/bugreport/
sun.cpu.endian=little
sun.io.unicode.encoding=UnicodeLittle
sun.desktop=windows
sun.cpu.isalist=amd64

Click the below link to download the code:
https://sites.google.com/site/ramj2eev1/home/javabasics/PropertiesDemo_system_modify_App.zip?attredirects=0&d=1

Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/PropertiesDemo_system_modify_App

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/2010ece32ddd64329464f57cc3a56f059cb8f810/BasicJava/PropertiesDemo_system_modify_App/?at=master

See also:

  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • Kids Tutorial
  • No comments:

    Post a Comment

    Google+ Followers

    Google+ Badge