易截截图软件、单文件、免安装、纯绿色、仅160KB

不明白的一道Java题!

Java code:
import java.io.IOException;
import java.io.File;
import java.io.RandomAccessFile;
class RandomFileTest
{
public static void main(String[] args) throws Exception
{
Student s1=new Student(1, "zhangsan", 90.5);
Student s2=new Student(2, "lisi", 98.5);
Student s3=new Student(3, "wangwu", 96.5);

File userDir=new File(System.getProperties().getProperty("user.dir"));
File tempFile=File.createTempFile("~student", ".tmp", userDir);
tempFile.deleteOnExit();

RandomAccessFile raf=new RandomAccessFile(tempFile, "rw");
s1.write(raf);
s2.write(raf);
s3.write(raf);
raf.seek(0);
Student s=new Student();
for(long i=0;i<raf.length();i=raf.getFilePointer())
{
s.read(raf);
System.out.println("[lenth:"+raf.length()+",i="+i+"] " + s);
}
raf.close();
Thread.sleep(5000);
}
}

class Student
{
int num;
String name;
double score;
public Student()
{
}
public Student(int num, String name, double score)
{
this.num=num;
this.name=name;
this.score=score;
}
public void write(RandomAccessFile raf) throws IOException
{
raf.writeInt(num);
raf.writeUTF(name);
raf.writeDouble(score);
}
public void read(RandomAccessFile raf) throws IOException
{
num=raf.readInt();
name=raf.readUTF();
score=raf.readDouble();
}
public String toString


相关问答:

在jsp中用session怎么实现购买功能 - Java / Web 开发

我想做够购物车用session 但是不知道怎么获取购买数量 谁有具体的代码吗 希望能割舍

下面是购物车的核心代码 
有了这个 就应该能够做出来吧
Java code:

public void doPost(HttpServletRequest reque ......

怎么用Java实现定时执行某程序 - Java / Java SE

我想用Java写一个程序,就是我想在运行代码后,在指定的时间打开某程序,例如我运行代码后,讲在12:00打开"D:\Program Files\Tencent\QQ2009\Bin\QQ.exe"这个程序,求高人指点。还有可能的话在指定的时间 ......

Java正则表达式,解析一个JSON字符串,在线等待...

Java code:

public static void main(String[] args)throws Exception {
String json="{\"installer_id\":\"00000003\",\"installer_name\":\"王五\& ......

java 取字段名

select a.name as parename ,b.name as chliname,a.typeId as paretype,b.typeid as chlitype from prodkind a inner join prodkind b where a.typeId=b.parentId
查出来的字段名称不是 parename 而是name
se ......

java程序连接SQlServer的问题 - Java / Java SE

import java.sql.Connection;
import java.sql.Date;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class QueryTest&n ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号