Topic: 有一句不明白什么意思(Long.valueof(args[1]).longValue())

  Print this page

1.有一句不明白什么意思(Long.valueof(args[1]).longValue()) Copy to clipboard
Posted by: newcall
Posted on: 2005-09-03 21:20

请尽量使用准确的文字描述作为标题
Your next post without a proper Subject will be removed.

Original subject :
有一句不明白什么意思,希望大家指点。


程序是显示指定文本文件最后N个字符.
code:

class RafDemo
{
public static void main(String args[])
{
try{
RandomAccessFile raf = new RandomAccessFile(args[0],"r");
long count =Long.valueof(args[1]).longValue(); //what's mean?
long position = raf.length();
position-=count;
if(position<0)
position=0;
raf.seek(position);
while(true)
{
try
{
byte b = raf.readByte();
System.out.print((char)b);

}catch(EOFException eofe)
{
break;
}
}
}catch(Exception e)
{
e.printStackTrace();
}
}
}

2.Re:有一句不明白什么意思(Long.valueof(args[1]).longValue()) [Re: newcall] Copy to clipboard
Posted by: why
Posted on: 2005-09-03 21:45

It's Long.valueOf
http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Long.html#valueOf(java.lang.String)
public static Long valueOf(String s)
throws NumberFormatException
Returns a Long object holding the value of the specified String. ...

http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Long.html#longValue()
public long longValue()
Returns the value of this Long as a long value.

3.Re:有一句不明白什么意思(Long.valueof(args[1]).longValue()) [Re: newcall] Copy to clipboard
Posted by: zcjl
Posted on: 2005-09-05 20:27

long count =Long.valueof(args[1]).longValue();

将一个String形式的数值(args[1])转换为long类型的值count
等价于:
long count = Long.parseLong(args[1]);

这几个方法的详细使用说明请查阅java.lang.Long的API文档


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923