Java Properties File Search Path Average ratng: 7,5/10 2166votes

When loading the Properties from a Class in the package com.al.common.email.templates you can use Properties prop = new Properties(); InputStream in = getClass().getResourceAsStream('foo.properties'); prop. Film Horror Indonesia Terbaru Ganool Ph. load(in); in.close(); (Add all the necessary exception handling). If your class is not in that package, you need to aquire the InputStream slightly differently: InputStream in = getClass().getResourceAsStream('/com/al/common/email/templates/foo.properties'); Relative paths (those without a leading '/') in getResource()/ getResourceAsStream() mean that the resource will be searched relative to the directory which represents the package the class is in.

Java Properties File Example

Using java.lang.String.class.getResource('foo.txt') would search for the (inexistent) file /java/lang/String/foo.txt on the classpath. Using an absolute path (one that starts with '/') means that the current package is ignored. The following two cases relate to loading a properties file from an example class named TestLoadProperties. Case 1: Loading the properties file using ClassLoader InputStream inputStream = TestLoadProperties.class.getClassLoader().getResourceAsStream('A.config'); properties.load(inputStream); In this case the properties file must be in the root/src directory for successful loading. Case 2: Loading the properties file without using ClassLoader InputStream inputStream = getClass().getResourceAsStream('A.config'); properties.load(inputStream); In this case the properties file must be in the same directory as the TestLoadProperties.class file for successful loading. Note: TestLoadProperties.java and TestLoadProperties.class are two different files. The former,.java file, is usually found in a project's src/ directory, while the latter,.class file, is usually found in its bin/ directory.

I am reading windows file paths from a properties file in Java. I do really need my program to handle unscaped paths, but so far I cannot see how to do it.

Java Properties File Search Path

How do I set or change the PATH system variable? This article applies to: • Platform(s): Oracle Linux, Red Hat Linux, SUSE Linux, Solaris SPARC, Windows 7, Windows 8, Windows Vista, Windows XP, Mac OS X The instructions on this page are intended for advanced users or system administrators.

General Information • The PATH is the system variable that your operating system uses to locate needed executables from the command line or Terminal window. • The PATH system variable can be set using System Utility in control panel on Windows, or in your shell's startup file on Linux and Solaris.