真金不怕火炼
package RandomTest;
/**
*
* @author Z
*/
import java.io.*;
public class RandomAccessFileTest1
{
/** Creates a new instance of RadomAccessFileTest */
File f=new File( "D:\\javaprogram\\src\\f1.txt ");//注意路径的表示
public int lenn=8;
public int lena=3;
public RandomAccessFileTest1()
{
String strc=new String( " ");
String strc1=new String( " ");
Person1 p1=new Person1( "王五 ",25, "男 ");
Person1 p2=new Person1( "李四 ",24, "男 ");
Person1 p3=new Person1( "张三 ",23, "女 ");
try
{
RandomAccessFile raf=new RandomAccessFile(f, "rw ");
raf.writeChars(p1.name);
raf.writeChars(new String().valueOf(p1.age));
raf.writeChars(p1.sex);
raf.seek(0);
while(lenn> 0)
{
strc1=strc1+raf.readChar();
lenn--;
}
System.out.println(strc);
while(lena> 0)
{
strc1=strc1+raf.readChar();
lena--;
}
System.out.println(strc1);