You can program a class path that allows you to specify a specific folder or series of folders for accessing data.
import java.io.IOException; import java.io.File; import java.net.URLClassLoader; import java.net.URL; import java.lang.reflect.Method; public class ClassPathHacker { private static final Class[] parameters = new Class[]{URL.class}; public static void addFile(String s) throws IOException { File f = new File(s); addFile(f); }
with property loader file
import java.io.InputStream; import java.util.Enumeration; import java.util.Locale; import java.util.Properties; import java.util.ResourceBundle; public abstract class PropertyLoader { public static Properties loadProperties (String name, ClassLoader loader) { if (name == null) throw new IllegalArgumentException ("null input: name"); if (name.startsWith ("/")) name = name.substring (1); if (name.endsWith (SUFFIX)) name = name.substring (0, name.length () - SUFFIX.length ()); Properties result = null; InputStream in = null; try { if (loader == null) loader = ClassLoader.getSystemClassLoader (); if (LOAD_AS_RESOURCE_BUNDLE) { name = name.replace ('/', '.');
then you can add the path as follows
try { //First Load up the properties and populate the config ClassPathHacker.addFile("/pathtomyapp"); } catch (IOException ex) { ex.printStackTrace(); } properties = PropertyLoader.loadProperties("myapp");
or you can also use getResourceBundle to get your resources, this is just one example of hacking the class path to allow access to files, you can always just add the class path programmatically and let the jar files you need to put there, therefore, if you always guarantee that the network path of the application is Q: you can add Q: \ to the classpath.
source share