Rollen Holt

来源:互联网 发布:死亡真面目知乎 编辑:程序博客网 时间:2024/06/05 08:55

/**

* @author rollen-holt jvm虚拟机的内存信息

*/

class hello{

public static void main(string[] args){

runtime run = runtime.getruntime();

system.out.println("jvm的最大内存量为:" + run.maxmemory());

system.out.println("jvm的空闲内存量为:" + run.freememory());

for(int i = 0; i

【运行结果】:

在我的计算机上的输出结果为:

jvm的最大内存量为:259522560

jvm的空闲内存量为:15931440

jvm的空闲内存量为:13478600

jvm的空闲内存量为:16070800

/**

* @author rollen-holt 使用runtime运行本机可运行程序

*/

class hello{

public static void main(string[] args){

runtime run = runtime.getruntime();

try{

run.exec("notepad.exe"); //打开记事本程序

}catch (exception e) {

e.printstacktrace();

}

}

}

【运行结果】:

会打开windows自带的记事本程序

/**

* @author rollen-holt

* 使用runtime运行本机可运行程序

* 并且使其5秒后自动关闭

*/

class hello{

public static void main(string[] args){

runtime run = runtime.getruntime();

process pro=null;

try{

pro=run.exec("notepad.exe"); //打开记事本程序

}catch (exception e) {

e.printstacktrace();

}

try{

thread.sleep(5000);

}catch (exception e) {

e.printstacktrace();

}

pro.destroy();

}

}

/*

* 此程序说明 exec的返回类型是process类型

* 如果要想使得进程消失,可以使用destroy方法

*/

关于国际化:

首先建立一个名称为:message.properties的文件

然后在里面写入

name=rollen holt

之后再同一个目录下建立一个.java文件。代码为:

import java.util.*;

class hello{

public static void main(string[] args){

resourcebundle res=resourcebundle.getbundle("message");

system.out.println(res.getstring("name"));

}

}

输出结果为:rollen holt

上面的例子有一个问题,如果在资源文件输入中文的话,会出现乱码,必须将中文转化为unicode编码

方法是:

比如我的目录是:f:\我的文件\我的资料\我的学习资料\我的程序\java\hello\src

下面有2个文件:

我们想将1.properties中的中文内容转化为unicode编码(目前里面的内容是:name=任文超)

cmd然后在命令行下:

首先定位到你的目录,对于笔者来说:

然后:

就会发现在目录下多了一个文件:

里面的内容是:

name=\u4efb\u6587\u8d85

然后编写程序代码:

import java.util.*;

class hello{

public static void main(string[] args){

locale zhloc=new locale("zh","cn");

resourcebundle res=resourcebundle.getbundle("message",zhloc);

system.out.println(res.getstring("name"));

}

}

输出的结果自然是:任文超

国际化之动态文本:

将name=你好,{0}!

转化为unicode编码,其余同上

然后编写代码:

import java.util.*;

import java.text.*;

class hello{

public static void main(string[] args){

locale zhloc=new locale("zh","cn");

resourcebundle res=resourcebundle.getbundle("message",zhloc);

string str=res.getstring("name");

system.out.println(messageformat.format(str, "任文超"));

}

}

输出结果:你好,任文超!

其实也可以使用类来替代资源文件的,但是在实际使用中很少使用类,此处就不说了,使用类是在太麻烦了。呵呵,留给有兴趣的朋友去干把。

如果你喜欢我喜欢的,你关心我关心的,大家交个朋友,一起分享,交流,进步。

我的邮箱:rollenholt#qq.com

我的新浪微博:http://weibo.com/rollenholt

我的腾讯微博:http://t.qq.com/rollenholt

绿色通道:好文要顶关注我收藏该文与我联系


======================================================
在最后,我邀请大家参加新浪APP,就是新浪免费送大家的一个空间,支持PHP+MySql,免费二级域名,免费域名绑定 这个是我邀请的地址,您通过这个链接注册即为我的好友,并获赠云豆500个,价值5元哦!短网址是http://t.cn/SXOiLh我创建的小站每天访客已经达到2000+了,每天挂广告赚50+元哦,呵呵,饭钱不愁了,\(^o^)/
原创粉丝点击