In the Java API, there are two ways to read resources using CLASSPATH.1. Class GetResource ()2. ClassLoader's GetResource ()But there are some differences between the two, run the following program: PackageZero.xml.config; Public classMain { Public
1. In Servlet/filter and other servlet web environments, as long as the javax. servlet. servletcontext type is obtained, the path can be obtained through getrealpath. The top-level directory in the relative path can be obtained through the parameter.
Document directory
Twostrategies for loading resource bundles and property files from Java code
About the author
Twostrategies for loading resource bundles and property files from Java code
By region mirroubtsov, javaworld.com, 11/22/02
From:
(a) Function: (1) class.getresource (String path) (2)Class.getClassLoader.getResource (String Path)where path in (2) cannot begin with '/' (1) path has no '/' both, meaning is differentTwoTo test the directory structure:|--project |--src
In the Java program release, many people will choose to use binary jar format for publishing, how to read the resources inside the jar?The main use of ClassLoader the following several methods to achieve:Public URL getresource (String name);Public
It seems easy to get files using Java, but for many new people like me, I still have a very simple understanding, and I feel quite deep in use, which is usually the most frequently used, is to use the file class of Java, suchTo obtain the
It seems easy to get files using Java, but for many new people like me, I still have a very simple understanding, and I feel quite deep in use, which is usually the most frequently used, is to use the file class in Java. To obtain the C:/test.txt
Project, some of the configuration files under current classpath are sometimes read. The code for the previously used read configuration file is as follows Public StaticProperties Loadpropertiesfile (String fileName) {Properties
Getresourceasstream: searches for resources with a given name. Return inputstreamgetresource: Find the resource path with the given name. Return URL
Simple Example: (Note: any class has a getclass () method)
Public class test {Public void
Error Caused by getservletcontext (). getresource ()
Tomcat4.1:
/*** Return a URL object of a resource that is mapped to* Specified context-relative path.** @ Param path context-relative path of the desired Resource** @ Exception
1. Create a new Java project;2, a new test package under the Src/main/java;3. Create a new Test.java file and file.txt file under the test package;4, Test.java file content is written as follows: Package test; Import Java.net.URL; Public class Test
Use this.getclass (). getClassLoader (). GetResource (""). GetPath () Gets the file path of the Chinese name and inserts the binary data into MySQL, but an error occurred, the print path, Find the path is garbled, it should feel likeThe problem of
getresource () and getResourceAsStream ()The compiled Java class file can be packaged as a jar file to run anywhere. But when we need to use some resources such as: an image, a piece of audio, you need to have a resource folder in the jar package,
When I wrote code several times, I encountered the use of getresource (). At that time, I wrote it in a common class to load images in assets, but the code reported an error. Later I found that this method requires context, but I was eager to write
The 1 GetResource method is the function that gets the file path.
such as: String Value=testmain2.class.getresource ("/a.properties"). ToString ();
This is the path to get the a.properties under SRC.
2 If the method argument starts with the SRC
Using java redis to implement redis Message Queue using jedisApplication scenarios
Recently, I am working on a project in the company and need to store chat content. Considering the high I/O connections and frequent connections in the database, I
In java, there are N methods to obtain the file path. Next I will introduce some examples of obtaining the path to help you.
1. Obtain the path from the java FileThread. currentThread (). getContextClassLoader (). getResource ("") // obtain the
1. understanding of basic conceptsAbsolute path: the absolute path is the real path of the file or directory on your home page on the hard disk (URL and physical path), for example:C: XYZ est.txt represents the absolute path of the test.txt file.
Tag: Data return lips get bin int () point thinking thinkPackage unit02;/** * * @time September 18, 2014 PM 10:29:48 * @porject Thinkinginjava * @author Kiwi */public class Test03 {privat E String getpathbypoint () {return This.getclass ().
Getting the path to the file in Java is unavoidable when we do the upload file operation.Running on the web1:This.getclass (). getClassLoader (). GetResource ("/"). GetPath ();This.getclass (). getClassLoader (). GetResource (""). GetPath (); The
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.