不明白的一道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
相关问答:
我想做够购物车用session 但是不知道怎么获取购买数量 谁有具体的代码吗 希望能割舍
下面是购物车的核心代码
有了这个 就应该能够做出来吧
Java code:
public void doPost(HttpServletRequest reque ......
我在eclipse中写了一个播放音乐的类,并把音乐文件和类文件放在了一起,结果运行时,出现错误,说是音乐文件那个是空的,但是在jcreator用同样的方法结果是可以运行的,请求高说指教,告诉为什么?急
你若是在Windo ......
在安装Java编译器的Eclipse的时候,对环境变量进行了配置,在安装MySQl的时候也要对环境变量进行配置;那么后面的配置会影响前面的Eclipse的配置吗?
请大家多指教~!谢谢!
不会把,我这都装了的 我系统里 还装了 ......
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 ......