以下内容介绍下java获取ip地址的几种思路. 1.直接利用java.net.InetAddress类获取,不过这种方法只在windows环境下有效,在linux环境下只能获取localhost地址(即/etc/hosts文件内容) 代码如下: import java.net.InetAddress; /** * This method works well in windows system. * In Linux system it returns 127.0.0.1 the content
这两天在研究Java调用打印机打印PDF文件的方法,学到了不少东西,特别来记录一下. 关于Java打印网上最多的而且也是Java正统的打印方法就是使用PrintService,一套比較标准的打印代码例如以下: public class PrintDemo { public static void main(String[] args) { JFileChooser fileChooser = new JFileChooser(); // 创建打印作业 int state = fileChoose
由于我需要用到java正则表达式提取地址中的ip和端口号,所以我就写了一个demo,测试一下,下面是demo public class Test0810_1 { public static void main(String[] args) { //通过控制板输入想要输入的地址,然后测试是否符合规则 Scanner a = new Scanner(System.in); String b = a.next(); //校验地址中是否存在 "ip:端口号" (例如rtsp://admin: