How to really read text file from classpath in Java

With the directory on the classpath, from a class loaded by the same classloader, you should be able to use either of: // From ClassLoader, all paths are “absolute” already – there’s no context // from which they could be relative. Therefore you don’t need a leading slash. InputStream in = this.getClass().getClassLoader() .getResourceAsStream(“SomeTextFile.txt”); // From … Read more

What is a classpath and how do I set it?

When programming in Java, you make other classes available to the class you are writing by putting something like this at the top of your source file: import org.javaguy.coolframework.MyClass; Or sometimes you ‘bulk import’ stuff by saying: import org.javaguy.coolframework.*; So later in your program when you say: MyClass mine = new MyClass(); The Java Virtual … Read more

Including all the jars in a directory within the Java classpath

Using Java 6 or later, the classpath option supports wildcards. Note the following: Use straight quotes (“) Use *, not *.jar Windows java -cp “Test.jar;lib/*” my.package.MainClass Unix java -cp “Test.jar:lib/*” my.package.MainClass This is similar to Windows, but uses : instead of ;. If you cannot use wildcards, bash allows the following syntax (where lib is … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)