In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces you to the Java file path example analysis, the content is very detailed, interested friends can refer to, hope to be helpful to you.
1. In Servlet web environments such as ServletFilter, as long as you get the javax.servlet.ServletContext type, you can use getRealPath ("...") Get the path. The topmost directory in the relative path can be obtained through the parameter "/".
Request.getSession (). GetServletContext () getRealPath ("/")
2. JSP Custom tag javax.servlet.jsp.tagext.TagSupport
((javax.servlet.ServletContext) pageContext) .getRealPath ("")
3. Used in normal Java Class object files:
ServletContext servletContext = ServletActionContext.getServletContext ()
String pathName = servletContext.getRealPath ("/")
This.getClass () .getResource
If the Class file is in the top-level directory (package) and "??" Is a blank string ("), and execution of this method in the jar file returns null. Each layer directory (package) below the top-level directory (package) returns the URL that contains the protocol. The folders (packages) of each layer are separated by "/".
Project location: C:project directory.
File location: C:projectTest.java
Contents of the file:
/ * source begin. * / public class Test {public Test () {System.out.println (this.getClass (). GetResource (")); System.out.println (this.getClass (). GetResource (". ")); System.out.println (this.getClass (). GetResource (" / ")); System.out.println (this.getClass (). GetResource (" Test.class ");} 4) ServletActionContext.getRequest () .getContextPath ()
Gets the path name configured in Tomcat.
2) A simple example of reading a JAVA file / / reading data into a character list char [] data = new char [10240]; int num=file.read (data); / / converting the character list into a string String str=new String (data,0,num); / / outputting in the console System.out.println ("Characters read=" + num); System.out.println (str); file.close ()
3) ergodic Mapre of Hash MAP. Iteratorit = ret.keySet (). Iterator (); while (it.hasNext ()) {String key = it.next (); String value = ret.get (key). ToString (); System.out.println ("Key:" + key); System.out.println ("Value:" + value);}
4) how to get the current time import java.text.SimpleDateFormat;import java.util.Date;Date today = new Date (); SimpleDateFormat df = new SimpleDateFormat ("yyyy-MM-dd"); return df.format (today)
5) IP address translation in character or host form to integer public static int inet_addr (String src) throws UnknownHostException {InetAddress address = InetAddress.getByName (src); int numeric_ip= 0BYTE [] buf= address.getAddress (); if ((buf! = null) & & (buf.length = = 4)) {numeric_ip= buf [3] & 0xFFX numeric address | = (buf [2]
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.