以下内容介绍下java获取ip地址的几种思路。1、直接利用java.net.InetAddress类获取,不过这种方法只在windows环境下有效,在linux环境下只能获取localhost地址(即/etc/hosts文件内容) 代码如下: 1import java.net.InetAddress;2 3/** 4 * This method works well in windows system.5 * In Linux system it returns 127.0.0.1 the content of the hosts file.6*/ 7publicstaticvoid getIpAddressInWindows() {8tr...
package test;import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;import javax.swing.JDialog;publicclass RuntimeCMD {privatestatic Process p;publicstaticvoid main(String[] args) throws IOException, InterruptedException {InputStream in=getInputStream("java -version");BufferedReader fr=new BufferedReader(new InputStreamReader(in));S...
方法一:在项目开发过程中,需要获取音视频文件时长。查询资料后发现 JAVE能够完美得到想要的结果,JAVE项目简介如下:The JAVE (Java Audio Video Encoder) library is Java wrapper on the ffmpeg project. Developers can take take advantage of JAVE to transcode audio and video files from a format to another. In example you can transcode an AVI file to a MPEG one, you can change a DivX video stream into a (you...
1、利用System.getProperty()函数获取当前路径: System.out.println(System.getProperty("user.dir"));//user.dir指定了当前的路径 2、使用File提供的函数获取当前路径: File directory = new File("");//设定为当前文件夹 try{ System.out.println(directory.getCanonicalPath());//获取标准的路径 System.out.println(directory.getAbsolutePath());//获取绝对路径 }catch(Exceptin e){} File.getCanonicalPath()和Fil...
提示用户输入两个数,然后输出用户输入的两数之和第一次输入 ,输入处为空第二个输入,输入处为默认27 (这里强调语句的使用)<html><head><meta http-equiv="content-type" content="text/html;charset=GB2312"/><title> 3.1 让用户输入两个数字,然后输出相加的结果 </title></head><body style="overflow:auto;padding:0px;margin:0px;"><div style="font-size:14px;font-weight:bold;color:white;font-family:Arial,宋体;background...
这里介绍的一个小技巧是如何用JavaScript获取页面上被选中的文字的方法。最关键的JavaScript API是:event.selection = window.getSelection();
这里的selection实际上是个对象,但如果我们使用 .toString()或强行转化成字符串,我们将得到被选中的文字。$(document).ready(function () {$(".contenttext").mouseup(function (e) {var txt;var parentOffset = $(this).offset();var x = e.pageX - parentOffset.left;var y = e.pag...
今天,我在尝试从数据库取数据的过程中,发现页面初始化时需要给时间控件赋初值。于是,我就写了一个获取当前年月的时间工具类。1、具体源码如下:YearAndMonth.java:/*** @Title:YearAndMonth.java* @Package:com.you.model* @Description:获取当前的年月* @Author: 游海东* @date: 2014年4月3日 下午10:44:12* @Version V1.2.3*/
package com.you.model;import java.util.Calendar;/*** @类名:YearAndMonth* @描述:* @Author:游...
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;/*** 获取两个时间段内的所有日期,日期可跨年*/publicclass GetBetweenDate {publicstaticvoid main(String[] args) {List<String> list = getBetweenDate("2013-12-01","2014-02-01");for(String date:list){System.out.println(date);}}publicstatic List<String> getBetweenDate(St...
java代码如下:package test;import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;public class Test {public static void main(String[] args) {Calendar now = Calendar.getInstance();System.out.println("年:" + now.get(Calendar.YEAR));System.out.println("月:" + (now.get(Calendar.MONTH) + 1));System.out.println("日:" + now.get(Calendar.DAY_OF_MONTH));System.out.println("时...
Session的追踪技术已知Session是利用cookie机制的server端技术。当client第一次訪问资源时 假设调用request.getSession() 就会在server端创建一个由浏览器独享的session空间,并分配一个唯一且名称为JSESSIONID的cookie发送到浏览器端,假设浏览器没有禁用cookie的话,当浏览器再次訪问项目中的Servlet程序时会将JSESSIONID带着。这时JSESSIONID就像唯一的一把钥匙 开启server端相应的session空间。进而获取到session中的内容(Se...
代码如下package Game;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.regex.Matcher;
import java.util.regex.Pattern;public class Main {public static void main(String[] args) throws IOException {File file=new File("D:\\index.html");BufferedReader buf=new BufferedReader(new InputStreamR...
今天分享一个免费在线的小工具的开发代码就是通过淘宝提供的接口获取服务商信息,工具地址:http://www.yzcopen.com/seo/ipadress代码如下:publicclass YzcPattern {
/**
* ip地址接口
*/privatefinalstatic String ipurl ="http://ip.taobao.com/service/getIpInfo.php?ip=";/**
* 判断ip
* @param text
* @return*/publicstaticboolean ipCheck(String text) {
if (text != null && !text.isEmpty()) {
// 定义正则表达式
Strin...
有时我们需要在js文件中用URL传来的参数,但是Javascript是客户端执行的脚本语言,而Session是服务器端的对象,我们不能直接取得Session中的值。那么,我们该如何在JS文件中获取URL中的参数呢?
下面介绍两种方式,一种是字符串拆分法,另一种是正则匹配法。第一种:字符串拆分法这种方式是通过location.search方法取得URL中的参数部分,然后再进一步处理得到的。具体代码如下:[javascript] //获取地址栏里(URL)传递的参数
f...
// 判断是否是手机function plat_is_mobile(){ var sUserAgent = navigator.userAgent.toLowerCase(); var bIsIpad = sUserAgent.match(/ipad/i) == "ipad"; var bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os"; var bIsMidp = sUserAgent.match(/midp/i) == "midp"; var bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4"; var bIsUc = sUserAgent.match(/ucw...
在Java8之前,代码编译为class文件后,方法参数的类型固定,但是方法名称会丢失,方法名称会变成arg0、arg1....。而现在,在Java8开始可以在class文件中保留参数名,这就给反射带来了极大的遍历。像mybatis等需要使用反射机制获取方法参数的时候就可以不用像以前一样需要使用类似于@Para之类的注解。功能测试代码参考自,点击进入编写测试类import java.lang.reflect.Method;import java.lang.reflect.Parameter;publicclass GetRun...