Try getting hold of a URL for your classpath resource:
URL url = this.getClass().getResource("/com/path/to/file.txt")
Then create a file using the constructor that accepts a URI:
File file = new File(url.toURI());
More Related Contents:
- What causes and what are the differences between NoClassDefFoundError and ClassNotFoundException?
- What is a classpath and how do I set it?
- Get a list of resources from classpath directory
- Find where java class is loaded from
- Java, Classpath, Classloading => Multiple Versions of the same jar/project
- Call “java -jar MyFile.jar” with additional classpath option
- Adding files to java classpath at runtime [duplicate]
- java.lang.ClassNotFoundException in spite of using CLASSPATH environment variable
- Eclipse “Error: Could not find or load main class”
- How to add directory to classpath in an application run profile in IntelliJ IDEA?
- Classpath does not work under linux
- NoClassDefFoundError while trying to run my jar with java.exe -jar…what’s wrong?
- Execute jar file with multiple classpath libraries from command prompt
- Is it possible to mix –class-path and –module-path in javac (JDK 9)?
- include external jar when running java -jar
- IntelliJ IDEA: “cannot resolve symbol” for String, System and other Java classes
- Including jar files in class path
- How can I save a file to the class path [closed]
- Java: NullPointerException from class.getResource( … )
- Can I create a custom classpath on a per application basis in Tomcat
- Adding jdbc driver to classpath
- Adding external resources to class-path in Tomcat 8
- Getting Ant to recognise a classpath
- How do I auto load a database jar in Groovy without using the -cp switch?
- How to run a java class with a jar in the classpath?
- How to read text file from classpath in Java?
- Adding to the classpath on OSX
- What’s the difference between a System property and environment variable
- TestNG ERROR Cannot find class in classpath
- What exactly is a class path in java?