File(\".\");//获取当前文件
.getAbsolutePath//获得文件绝对路径
.length//获得文件长度
.list//取得文件list是个
.exists//文件存在
.isFile//文件是文件
.isDirectory//文件是目录
/**文件名过滤器*/
Filter implements FilenameFilter
{
String canShu;
Filter ( String canShu )
{
this.canShu = canShu ;
}
public boolean accept ( File dir ,String name)
{
name.endsWith(\".\"+canShu );
}
}
/**随机文件创建并写入内容操作*/
void CreateFile(RandomAccessFile rafFile)
{
long lngNumbers = { 10001L,10002L,10003L,10004L,10005L };
String strNames = { \"zhang san\",\"li si\",\"wang wu\",\"zhao liu\",\"qian qi\" };
Age = { 20,21,26,18,30 };
try
{
for ( i =0 ; i < lngNumbers.length ; i )
{
rafFile.writeLong(lngNumbers[i]);
rafFile.writeChar(\'\\t\');
rafFile.writeInt(Age[i]);
rafFile.writeChar(\'\\t\');
rafFile.writeBytes(strNames[i]+\"\\n\");
}
}catch(IOException e)
{
.out.prln (\" File Access Error !\"+e);
}
}
/**输出文件内容*/
void OutputFile(RandomAccessFile rafFile)
{
try
{
.out.prln(\"显示文件内容:\");
rafFile.seek(0);
while (true)
{
long lngNumber = rafFile.readLong;
rafFile.readChar;
str = rafFile.readInt;
.out.prln(lngNumber + \"\\t\" + str + \"\\t\" + rafFile.readLine);
}
}
catch(EOFException e)
{
.out.prln (\"Reach the end of the file ! \"+e);
}
catch(IOException e)
{
.out.prln (\" File Access Error !\"+e);
}
}
最新评论