|
10Java金币
package Calculate;
import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
public class CalculateDemo {
@SuppressWarnings("resource")
public void cDemo() throws IOException{
int math1 = 0;
int english1 = 0;
int java1 = 0;
float ave1 = 0;
File f = new File("d:"+File.separator+"zhangshuai"+File.separator+"201416010417.txt");
RandomAccessFile rdf = null;
rdf = new RandomAccessFile(f,"r");
rdf.skipBytes(52);
rdf.seek(24);
math1 = rdf.readInt();
rdf.seek(36);
english1 = rdf.readInt();
rdf.seek(48);
java1 = rdf.readInt();
ave1 = (math1+english1+java1)/3;
System.out.println("Math:"+math1+"English:"+english1+"Java:"+java1); //用于验证是否读取到
System.out.print("Ave:"+ave1);
}
}
在txt文件中 有科目的具体分数。为什么出来的时候是这样的。
|
|